MCPcopy Create free account
hub / github.com/ipython/ipython / showtraceback

Method showtraceback

IPython/core/interactiveshell.py:2007–2059  ·  view source on GitHub ↗

Display the exception that just occurred. If nothing is known about the exception, this is the method which should be used throughout the code for presenting user tracebacks, rather than directly invoking the InteractiveTB object. A specific showsyntaxerror() also e

(self, exc_tuple=None, filename=None, tb_offset=None,
                      exception_only=False, running_compiled_code=False)

Source from the content-addressed store, hash-verified

2005 return ''.join(msg)
2006
2007 def showtraceback(self, exc_tuple=None, filename=None, tb_offset=None,
2008 exception_only=False, running_compiled_code=False):
2009 """Display the exception that just occurred.
2010
2011 If nothing is known about the exception, this is the method which
2012 should be used throughout the code for presenting user tracebacks,
2013 rather than directly invoking the InteractiveTB object.
2014
2015 A specific showsyntaxerror() also exists, but this method can take
2016 care of calling it if needed, so unless you are explicitly catching a
2017 SyntaxError exception, don't try to analyze the stack manually and
2018 simply call this method."""
2019
2020 try:
2021 try:
2022 etype, value, tb = self._get_exc_info(exc_tuple)
2023 except ValueError:
2024 print('No traceback available to show.', file=sys.stderr)
2025 return
2026
2027 if issubclass(etype, SyntaxError):
2028 # Though this won't be called by syntax errors in the input
2029 # line, there may be SyntaxError cases with imported code.
2030 self.showsyntaxerror(filename, running_compiled_code)
2031 elif etype is UsageError:
2032 self.show_usage_error(value)
2033 else:
2034 if exception_only:
2035 stb = ['An exception has occurred, use %tb to see '
2036 'the full traceback.\n']
2037 stb.extend(self.InteractiveTB.get_exception_only(etype,
2038 value))
2039 else:
2040 try:
2041 # Exception classes can customise their traceback - we
2042 # use this in IPython.parallel for exceptions occurring
2043 # in the engines. This should return a list of strings.
2044 stb = value._render_traceback_()
2045 except Exception:
2046 stb = self.InteractiveTB.structured_traceback(etype,
2047 value, tb, tb_offset=tb_offset)
2048
2049 self._showtraceback(etype, value, stb)
2050 if self.call_pdb:
2051 # drop into debugger
2052 self.debugger(force=True)
2053 return
2054
2055 # Actually show the traceback
2056 self._showtraceback(etype, value, stb)
2057
2058 except KeyboardInterrupt:
2059 print('\n' + self.get_exception_only(), file=sys.stderr)
2060
2061 def _showtraceback(self, etype, evalue, stb):
2062 """Actually show a traceback.

Callers 15

excepthookMethod · 0.95
safe_execfileMethod · 0.95
safe_execfile_ipyMethod · 0.95
safe_run_moduleMethod · 0.95
_run_cellMethod · 0.95
run_cell_asyncMethod · 0.95
run_ast_nodesMethod · 0.95
run_codeMethod · 0.95
triggerMethod · 0.80
init_gui_pylabMethod · 0.80
_run_exec_linesMethod · 0.80
_run_startup_filesMethod · 0.80

Calls 7

_get_exc_infoMethod · 0.95
showsyntaxerrorMethod · 0.95
show_usage_errorMethod · 0.95
get_exception_onlyMethod · 0.95
_showtracebackMethod · 0.95
debuggerMethod · 0.95
structured_tracebackMethod · 0.45

Tested by 1

my_handlerMethod · 0.64