A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-February/132632.html below:

[Python-Dev] PEP 463: Exception-catching expressions

[Python-Dev] PEP 463: Exception-catching expressions [Python-Dev] PEP 463: Exception-catching expressionsGreg Ewing greg.ewing at canterbury.ac.nz
Sat Feb 22 02:55:16 CET 2014
Steven D'Aprano wrote:

>     result = computation(
>                  int(arg) except ValueError: abort("Invalid int")
>                  )
> 
> Actually, not quite so nice as I first thought, since you're relying on 
> the side-effects of abort() rather than returning a value.

Yeah, while I was writing that I wondered whether
you should be allowed to write

    int(arg) except ValueError: raise UserError("Invalid int")

That looks heretical, because 'raise' can't in any
way be interpreted as a value-returning expression.
But you can achieve the same result using a function
that always raises and exception, so forbidding it
on those grounds would be pointless.

And writing it that way at least makes it obvious that
it *does* always raise an exception, in the same way
that

    try:
        i = int(arg)
     except ValueError:
        raise UserError("Invalid int")
     else:
        result = computation(i)

makes it obvious that control can't fall off the
end of the except branch.

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4