exception 

Send to Kindle
home » snippets » python » exception



Notes

Snippets

Inner Exceptions

python 2.X

import sys

try:
    ...
except SomeException as e:
  traceback = sys.exc_info()[2]
  new_exception = NewException("{exception}.  While performing operation {OP}.".format(
                               exception=e, OP="operation"))
  raise new_exception, None, traceback

python 3.x: with_traceback

See BaseException

try:
    ...
except SomeException:
    traceback = sys.exc_info()[2]
    raise OtherException(...).with_traceback(traceback)