I want to catch all uncaught exceptions in my application, log them, then 
handle as normal. Which, in practice, means a traceback. Is this the 
right way to do it?



import logging
import sys

logger = logging.getLogger('mylogger')

def my_handler(type, value, tb):
    msg = "Uncaught %s: %s" % (type, value)
    logger.exception(msg)
    sys.__excepthook__(type, value, tb)


# Install exception handler
sys.excepthook = my_handler

# Run your main script here:
if __name__ == '__main__':
    main()


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to