MCPcopy Index your code
hub / github.com/python/cpython / default_exception_handler

Method default_exception_handler

Lib/asyncio/base_events.py:1845–1893  ·  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

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

Callers 1

Calls 5

getMethod · 0.45
joinMethod · 0.45
rstripMethod · 0.45
appendMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected