[Python-Dev] PEP 463: Exception-catching expressions
Ethan Furman
ethan at stoneleaf.us
Sat Feb 22 02:28:30 CET 2014
On 02/21/2014 05:21 PM, Steven D'Aprano wrote:
> On Sat, Feb 22, 2014 at 01:15:13PM +1300, Greg Ewing wrote:
>>
>> With an except expression, it could be written:
>>
>> result = computation(int(arg)
>> except ValueError: abort("Invalid int"))
>
> Nice example! Except I'd lay the code out a bit better to emphasise
> which part is being guarded:
>
> 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.
Think of it rather as transforming the exception to be more useful.
--
~Ethan~
More information about the Python-Dev
mailing list