The Python idiom for reraising a primary exception fails when the except block raises a
- class toil.lib.exceptions.panic(log=None)¶
The Python idiom for reraising a primary exception fails when the except block raises a secondary exception, e.g. while trying to cleanup. In that case the original exception is lost and the secondary exception is reraised. The solution seems to be to save the primary exception info as returned from sys.exc_info() and then reraise that.
This is a contextmanager that should be used like this
# do something that can fail
- with panic( log ):
# do cleanup that can also fail
If a logging logger is passed to panic(), any secondary Exception raised within the with block will be logged. Otherwise those exceptions are swallowed. At the end of the with block the primary exception will be reraised.
- toil.lib.exceptions.raise_(exc_type, exc_value, traceback)¶
- Return type: