2.2 features

Paul Prescod paulp at ActiveState.com
Fri Aug 3 20:51:33 CEST 2001


Guido van Rossum wrote:
> 
> Paul Prescod <paulp at ActiveState.com> writes:
> 
> > try:
> >   foo()
> > except x in class ZeroDivisionError:
> >   bar()
> 
> That would be backwards incompatible.   The expression in the except
> clause is not an arbitrary Boolean -- it's an exception or a tuple of
> exceptions.  

I don't see it as an arbitrary boolean. I see it as a very fixed
structure:

'except' varname 'in' 'class' ExceptionName[, ExceptionName]* ':'

For example, this would be illegal:

   except x not in class ZeroDivisionError:

Yes "x in class y" would be a boolean expression elsewhere but that's
just like the current exception syntax which looks like a tuple
constructor but isn't really. Either we try to reuse syntax or we don't.
If we chose NOT to reuse syntax then we could say:

try:
  foo()
except x of type ZeroDevisionError:
  bar()

i.e. we have complete control over what follows the "except" clause. We
could even introduce contextual keywords. If you tell me which strategy
you prefer, I can write a PEP.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list