Created
April 13, 2012 18:15
-
-
Save jdunck/2378892 to your computer and use it in GitHub Desktop.
unpickleable why?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wat | |
from pickle import dumps | |
try: | |
wat.b() | |
except Exception, the_exc: | |
exc = the_exc | |
print dumps(exc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FrobExc(Exception): | |
pass | |
class OtherExc(Exception): | |
pass | |
def a(): | |
raise FrobExc('wark`') | |
def b(): | |
try: | |
a() | |
except FrobExc, e: | |
exc_msg = str(e) | |
# munge exc but keep original traceback. | |
# gross, but see: http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/ | |
import sys | |
exc_class, exc, tb = sys.exc_info() | |
new_exc = OtherExc() | |
raise new_exc.__class__, new_exc, tb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment