MCPcopy Index your code
hub / github.com/RustPython/RustPython / default_exception_handler

Method default_exception_handler

Lib/asyncio/base_events.py:1827–1875  ·  view source on GitHub ↗

Default exception handler. This is called when an exception occurs and no exception handler is set, and can be called by a custom exception handler that wants to defer to the default behavior. This default handler logs the error message and other context-dep

(self, context)

Source from the content-addressed store, hash-verified

1825 self._exception_handler = handler
1826
1827 def default_exception_handler(self, context):
1828 """Default exception handler.
1829
1830 This is called when an exception occurs and no exception
1831 handler is set, and can be called by a custom exception
1832 handler that wants to defer to the default behavior.
1833
1834 This default handler logs the error message and other
1835 context-dependent information. In debug mode, a truncated
1836 stack trace is also appended showing where the given object
1837 (e.g. a handle or future or task) was created, if any.
1838
1839 The context parameter has the same meaning as in
1840 `call_exception_handler()`.
1841 """
1842 message = context.get('message')
1843 if not message:
1844 message = 'Unhandled exception in event loop'
1845
1846 exception = context.get('exception')
1847 if exception is not None:
1848 exc_info = (type(exception), exception, exception.__traceback__)
1849 else:
1850 exc_info = False
1851
1852 if ('source_traceback' not in context and
1853 self._current_handle is not None and
1854 self._current_handle._source_traceback):
1855 context['handle_traceback'] = \
1856 self._current_handle._source_traceback
1857
1858 log_lines = [message]
1859 for key in sorted(context):
1860 if key in {'message', 'exception'}:
1861 continue
1862 value = context[key]
1863 if key == 'source_traceback':
1864 tb = ''.join(traceback.format_list(value))
1865 value = 'Object created at (most recent call last):\n'
1866 value += tb.rstrip()
1867 elif key == 'handle_traceback':
1868 tb = ''.join(traceback.format_list(value))
1869 value = 'Handle created at (most recent call last):\n'
1870 value += tb.rstrip()
1871 else:
1872 value = repr(value)
1873 log_lines.append(f'{key}: {value}')
1874
1875 logger.error('\n'.join(log_lines), exc_info=exc_info)
1876
1877 def call_exception_handler(self, context):
1878 """Call the current event loop's exception handler.

Callers 1

Calls 7

sortedFunction · 0.85
reprFunction · 0.85
getMethod · 0.45
joinMethod · 0.45
rstripMethod · 0.45
appendMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected