Skip to content

Instantly share code, notes, and snippets.

@jdunck
Created April 13, 2012 18:15
Show Gist options
  • Save jdunck/2378892 to your computer and use it in GitHub Desktop.
Save jdunck/2378892 to your computer and use it in GitHub Desktop.
unpickleable why?
import wat
from pickle import dumps
try:
wat.b()
except Exception, the_exc:
exc = the_exc
print dumps(exc)
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