Get last exception in pdb
You can retrieve the latest exception in pdb/ipdb via:
__exception__
The above is actually a tuple of the (exception, message).
Is this what you are looking for?
import pdb
try:
1/0
except Exception as err:
pdb.set_trace()
% test.py
--Return--
> /home/unutbu/pybin/test.py(8)<module>()->None
-> pdb.set_trace()
(Pdb) err
ZeroDivisionError('integer division or modulo by zero',)
(Pdb) quit
If you do not want to modify the code where the exception originates, you could instead redefine sys.excepthook
:
import pdb
import sys
def excepthook(type, value, traceback):
pdb.set_trace()
sys.excepthook = excepthook
1/0
% test.py
--Return--
> /home/unutbu/pybin/test.py(7)excepthook()->None
-> pdb.set_trace()
(Pdb) type
<type 'exceptions.ZeroDivisionError'>
(Pdb) value
ZeroDivisionError('integer division or modulo by zero',)
(Pdb) traceback
<traceback object at 0xb774f52c>
(Pdb)