code: def _log_unhandled_exception_and_exit(cls, exc_class=None, exc=None, tb=None, add_newline=False):
      
      exc_class = exc_class or sys.exc_info()[0]
      exc = exc or sys.exc_info()[1]
      tb = tb or sys.exc_info()[2]
  
      # This exception was raised by a signal handler with the intent to exit the program.
      if exc_class == SignalHandler.SignalHandledNonLocalExit:
        return cls._handle_signal_gracefully(exc.signum, exc.signame, exc.traceback_lines)
  
      extra_err_msg = None
      try:
        # Always output the unhandled exception details into a log file, including the traceback.
        exception_log_entry = cls._format_unhandled_exception_log(exc, tb, add_newline,
                                                                  should_print_backtrace=True)
        cls.log_exception(exception_log_entry)
      except Exception as e:
        extra_err_msg = 'Additional error logging unhandled exception {}: {}'.format(exc, e)
        logger.error(extra_err_msg)
  
      # Generate an unhandled exception report fit to be printed to the terminal (respecting the
      # Exiter's should_print_backtrace field).
      stderr_printed_error = cls._format_unhandled_exception_log(
        exc, tb, add_newline,
        should_print_backtrace=cls._should_print_backtrace_to_terminal)
      if extra_err_msg:
        stderr_printed_error = '{}\n{}'.format(stderr_printed_error, extra_err_msg)
      cls._exit_with_failure(stderr_printed_error)
docs: A sys.excepthook implementation which logs the error and exits with failure.