catching exceptions from an except: block

Paul Rubin http
Thu Mar 8 19:19:27 EST 2007


Steven D'Aprano <steve at REMOVEME.cybersource.com.au> writes:
> I thought "raise" on its own was supposed to re-raise the previous
> exception, but I've just tried it in the interactive interpreter and it
> doesn't work for me.

It means you can catch an exception, do stuff with it, and then pass
it upward to earlier callers:

    def foo(n):
       try:
          bar(n)
       except (ValueError, TypeError):
          print "invalid n:", n
          raise  # re-signal the same error to foo's caler



More information about the Python-list mailing list