1, pending exception

  1. import sys
  2. class CustomException(Exception):
  3. """
  4. Wrap arbitrary pending exception,
  5. if any, in addition to other info.
  6. """
  7. def __init__(self, *args):
  8. Exception.__init__(self, *args)
  9. self.wrapped_exc = sys.exc_info()
  10. def call_wrapped(callable, *args, **kwargs):
  11. try:
  12. return callable(*args, **kwargs)
  13. except:
  14. raise CustomException('Wrapped function '
  15. 'propagated exception')
  16. def f(x):
  17. return 1 / x
  18. a = call_wrapped(f, 0)
  19. print(a)