@@ -377,8 +377,7 @@ def user_exception(self, frame, exc_info):
377
377
# stop when the debuggee is returning from such generators.
378
378
prefix = 'Internal ' if (not exc_traceback
379
379
and exc_type is StopIteration ) else ''
380
- self .message ('%s%s' % (prefix ,
381
- traceback .format_exception_only (exc_type , exc_value )[- 1 ].strip ()))
380
+ self .message ('%s%s' % (prefix , self ._format_exc (exc_value )))
382
381
self .interaction (frame , exc_traceback )
383
382
384
383
# General interaction function
@@ -851,7 +850,7 @@ def checkexpr(self, expr):
851
850
try :
852
851
compile (expr , "<stdin>" , "eval" )
853
852
except SyntaxError as exc :
854
- return _rstr (traceback . format_exception_only (exc )[ - 1 ]. strip ( ))
853
+ return _rstr (self . _format_exc (exc ))
855
854
return None
856
855
857
856
def do_enable (self , arg ):
@@ -1267,12 +1266,11 @@ def _getval_except(self, arg, frame=None):
1267
1266
else :
1268
1267
return eval (arg , frame .f_globals , frame .f_locals )
1269
1268
except BaseException as exc :
1270
- err = traceback .format_exception_only (exc )[- 1 ].strip ()
1271
- return _rstr ('** raised %s **' % err )
1269
+ return _rstr ('** raised %s **' % self ._format_exc (exc ))
1272
1270
1273
1271
def _error_exc (self ):
1274
- exc_info = sys .exc_info ()[: 2 ]
1275
- self .error (traceback . format_exception_only ( * exc_info )[ - 1 ]. strip ( ))
1272
+ exc = sys .exc_info ()[1 ]
1273
+ self .error (self . _format_exc ( exc ))
1276
1274
1277
1275
def _msg_val_func (self , arg , func ):
1278
1276
try :
@@ -1664,6 +1662,9 @@ def _run(self, target: Union[_ModuleTarget, _ScriptTarget]):
1664
1662
1665
1663
self .run (target .code )
1666
1664
1665
+ def _format_exc (self , exc : BaseException ):
1666
+ return traceback .format_exception_only (exc )[- 1 ].strip ()
1667
+
1667
1668
1668
1669
# Collect all command help into docstring, if not run with -OO
1669
1670
0 commit comments