Kann man dann so verwenden:
http://paste.pocoo.org/show/142836/
Code: Alles auswählen
>>> handler
<__main__.PyExceptionHandler object at 0xb7d4de2c>
>>> with handler.catch():
... 1+2
...
3
>>> handler.exception
>>>
>>> with handler.catch():
... int('a')
...
>>> handler.exception
ValueError("invalid literal for int() with base 10: 'a'",)
>>>
>>> with handler.catch(TypeError, RuntimeError):
... int('a')
...
Traceback (most recent call last):
File "<console>", line 2, in <module>
ValueError: invalid literal for int() with base 10: 'a'