Say I have something like this, which sends unhanded exceptions to logging.critical()
:
import sys
def register_handler():
orig_excepthook =
You should use sys.__excepthook__
[1].
It is an object that contains the original values of sys.excepthook
[2] at the start of the program.
ie;
import sys
import logging
def register_handler():
log = logging.getLogger(__name__)
def error_catcher(*exc_info):
log.critical("Unhandled exception", exc_info=exc_info)
sys.__excepthook__(*exc_info)
sys.excepthook = error_catcher
Reference:
1. https://docs.python.org/3/library/sys.html#sys.excepthook
2. https://docs.python.org/3/library/sys.html#sys.excepthook