@@ -1258,7 +1258,7 @@ def _getval_except(self, arg, frame=None):
1258
1258
return _rstr ('** raised %s **' % self ._format_exc (exc ))
1259
1259
1260
1260
def _error_exc (self ):
1261
- exc = sys .exc_info ()[ 1 ]
1261
+ exc = sys .exception ()
1262
1262
self .error (self ._format_exc (exc ))
1263
1263
1264
1264
def _msg_val_func (self , arg , func ):
@@ -1755,9 +1755,10 @@ def post_mortem(t=None):
1755
1755
"""
1756
1756
# handling the default
1757
1757
if t is None :
1758
- # sys.exc_info() returns (type, value, traceback) if an exception is
1759
- # being handled, otherwise it returns None
1760
- t = sys .exc_info ()[2 ]
1758
+ exc = sys .exception ()
1759
+ if exc is not None :
1760
+ t = exc .__traceback__
1761
+
1761
1762
if t is None :
1762
1763
raise ValueError ("A valid traceback must be passed if no "
1763
1764
"exception is being handled" )
@@ -1841,18 +1842,18 @@ def main():
1841
1842
except Restart :
1842
1843
print ("Restarting" , target , "with arguments:" )
1843
1844
print ("\t " + " " .join (sys .argv [1 :]))
1844
- except SystemExit :
1845
+ except SystemExit as e :
1845
1846
# In most cases SystemExit does not warrant a post-mortem session.
1846
1847
print ("The program exited via sys.exit(). Exit status:" , end = ' ' )
1847
- print (sys . exc_info ()[ 1 ] )
1848
+ print (e )
1848
1849
except SyntaxError :
1849
1850
traceback .print_exc ()
1850
1851
sys .exit (1 )
1851
- except :
1852
+ except BaseException as e :
1852
1853
traceback .print_exc ()
1853
1854
print ("Uncaught exception. Entering post mortem debugging" )
1854
1855
print ("Running 'cont' or 'step' will restart the program" )
1855
- t = sys . exc_info ()[ 2 ]
1856
+ t = e . __traceback__
1856
1857
pdb .interaction (None , t )
1857
1858
print ("Post mortem debugger finished. The " + target +
1858
1859
" will be restarted" )
0 commit comments