0

I have a dict like this:

{
  "stackTrace": [
    ["/path/to/some/code.py", 10, "some_function", "do_something()"],
    ["/path/to/some/code.py", 20, "do_something", "raise MyException('aaaa')"]
  ],
  "errorType": "MyException",
  "errorMessage": "aaaa",
}

I can make it pretty with traceback.format_list but I was wondering if there was a way to reconstruct the actual exception and raise it. I figure I can dynamically create the exception type and use the same message but how can I preserve the stack trace?

edit: so, I've tried this, but I'm stuck on turning the stackTrace in my dict into a traceback object. I've no idea how to do it - apparently it is very difficult to do so I'm wondering if there's a different way to accomplish what I want.

raise type(mydict['errorType'], (Exception,), {}), mydict['errorMessage'], traceback???
Community
  • 1
  • 1
2rs2ts
  • 10,662
  • 10
  • 51
  • 95
  • Maybe just use an ordered dict? Not sure what it is you are asking though.. – Montmons Mar 22 '17 at 23:31
  • I want to raise an exception with that type, value, and traceback as if it had occurred in my code, even though all I have is this dict. – 2rs2ts Mar 22 '17 at 23:42

0 Answers0