[Python-ideas] syntax to continue into the next subsequent except block

Guido van Rossum guido at python.org
Mon Sep 17 06:20:55 CEST 2012

On Sun, Sep 16, 2012 at 5:11 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>> The suggestion to add ad-hoc "if <condition>" clauses to random parts
>> of the syntax doesn't appeal to me at all.
> I wouldn't call it a random part of the syntax. This is
> not like the proposals to add if-clauses to while loops,
> for loops, etc -- they would just be minor syntactic sugar.
> This proposal addresses something that is quite awkward to
> express using existing constructs.

It can address an important use case and still be a random syntax
change. I'm sure there are possible refactorings of the error handling
from the examples that make it a lot less awkward. I don't think I've
ever had a use case in my own code where I found it particularly
awkward that I couldn't jump from one except clause to the next; I do
remember some cases where I could simply write

    <code that may fail>
  except <some exception>, err:
    if <on further inspection we don't want to handle it>:
      raise    # re-raise err
    <special handling for some variant of the exception>

This would possibly be combined with other except clauses but the
would be no need for the 'raise' to transfer to one of these.

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list