Skip to content

Instantly share code, notes, and snippets.

@bcho
Created December 29, 2012 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcho/4404326 to your computer and use it in GitHub Desktop.
Save bcho/4404326 to your computer and use it in GitHub Desktop.
#coding: utf-8
import sys
class CustomException(Exception):
'''Wrap arbitray pending exception, if any, in addition to other info.'''
def __init__(self, *args):
super(CustomException, self).__init__(*args)
self.wrapped_exc = sys.exc_info()
class AlwaysWrongException(Exception):
'''Always do it wrong.'''
def call_wrapped(callable, *args, **kwargs):
try:
return callable(*args, **kwargs)
except:
raise (CustomException, "Wrapped function propagated exception.")
def always_wrong(*args, **kwargs):
raise AlwaysWrongException
if __name__ == '__main__':
try:
call_wrapped(always_wrong)
except CustomException, e:
print e.wrapped_exc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment