[Python-ideas] except expression

Ron Adam ron3200 at gmail.com
Tue Feb 18 02:31:10 CET 2014



On 02/17/2014 03:40 PM, Greg Ewing wrote:
> Chris Angelico wrote:
>> Do you mean that there may not be a comma, or that commas must be
>> surrounded by parens?
>
> Commas would need to be surroounded by parens.
>
>> Imagine if the exception
>> list isn't literals, but comes from somewhere else (which is perfectly
>> legal). How do you eyeball it and see that this is now a new except
>> clause?
>
> I'm not a big fan of this idea either. It seems
> to me that wanting more than one except clause is
> going to be *extremely* rare, so it's not worth
> going out of our way to make it super-concise.

I agree, and adding too much too soon, could limit options for later 
enhancement.

In the recent thread on enhanced exceptions, it's suggested we add more 
information to exceptions.

I have a different point of view that would have an effect on this idea.

To me, the added information on exceptions, should also be usable, 
preferable to allow more control on catching exceptions.

For example:.

     value = expr1 except IndexError from foo: expr2

Where the exception caught is one raised in "foo".  While other 
IndexError's are allowed to bubble out.

We can't use else... although that would be my first choice if else wasn't 
already used differently in except and for statements.

To explain a bit further, when you get a trace back from an uncaught 
exception, the last line of the trace back contains the function it 
happened in.  But that info is difficult to get from a caught exception.
It's even nicer to be able to use it to specify more precisely what 
exceptions to catch.

Cheers,
    Ron




More information about the Python-ideas mailing list