14.10 re-throw the caught exception?
You caught an except
exception in a block and now want to re-throw it.
Solution?
Simply use a single rasie
statement, for example:
>>>DefExample():...Try:...int ( ' n/a ' ) ... except valueerror: ... print ( "didn ' t work" ) ... raise ... >>> example () didn ' t work traceback (most recent call last): File "<stdin>", line 1, in span class= "n" ><module> File "<stdin>", line 3, in Examplevalueerror: invalid literal for int. () with base: ' N/a ' > >>
Discuss?
The problem is usually when you need to perform an action (such as logging, cleanup, etc.) after catching an exception, but then you want to propagate the exception.
A very common usage is in the processor that captures all exceptions:
Try: ... eraise
Albert (http://www.aibbt.com/) The first artificial intelligence portal in China
Python Cookbook (3rd edition) Chinese version: 14.10 re-throw caught exception