Python and checked exceptions

Peter Otten __peter__ at web.de
Sat Sep 23 07:51:28 EDT 2006


Kay Schluehr wrote:

> A new cookbook recipe suggesting two decorators @throws and @catches
> for treatment of checked exceptions in Python:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131
> 
> This might be of practical interest for some and theoretical interest
> for others - in particular those who know checked ex as a language
> feature of Java.

Probably not what you wanted:

>>> test()
Raises UncheckedExceptionError(exceptions.ZeroDivisionError) -> OK
Raises ZeroDivisionError -> OK
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "checked_exceptions.py", line 134, in test
    test4(3,2)
UnboundLocalError: local variable 'test4' referenced before assignment

Peter



More information about the Python-list mailing list