def call_exception_handler(self, context): if self._exception_handler is None: try: self.default_exception_handler(context) except Exception: # Second protection layer for unexpected errors # in the default implementation, as well as for subclassed # event loops with overloaded "default_exception_handler". logger.error('Exception in default exception handler', exc_info=True) else: try: self._exception_handler(self, context) except Exception as exc: # Exception in the user set custom exception handler. try: # Let's try default handler. self.default_exception_handler({ 'message': 'Unhandled error in exception handler', 'exception': exc, 'context': context, }) except Exception: # Guard 'default_exception_handler' in case it's # overloaded. logger.error( 'Exception in default exception handler ' 'while handling an unexpected error ' 'in custom exception handler', exc_info=True)
def call_exception_handler(self, context): if self._exception_handler is None: try: self.default_exception_handler(context) except Exception: # Second protection layer for unexpected errors # in the default implementation, as well as for subclassed # event loops with overloaded "default_exception_handler". logger.error('Exception in default exception handler', exc_info=True) else: try: self._exception_handler(self, context) except Exception as exc: # Exception in the user set custom exception handler. try: # Let's try default handler. self.default_exception_handler({ 'message': 'Unhandled error in exception handler', 'exception': exc, 'context': context, }) except Exception: # Guard 'default_exception_handler' in case it's # overloaded. logger.error('Exception in default exception handler ' 'while handling an unexpected error ' 'in custom exception handler', exc_info=True)
def default_exception_handler(self, context): message = context.get('message') if not message: message = 'Unhandled exception in event loop' exception = context.get('exception') if exception is not None: if hasattr(exception, '__traceback__'): # Python 3 tb = exception.__traceback__ else: # call_exception_handler() is usually called indirectly # from an except block. If it's not the case, the traceback # is undefined... tb = sys.exc_info()[2] exc_info = (type(exception), exception, tb) else: exc_info = False log_lines = [message] for key in sorted(context): if key in ('message', 'exception'): continue log_lines.append('{0}: {1!r}'.format(key, context[key])) logger.error('\n'.join(log_lines), exc_info=exc_info)