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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…