I cannot work out how to log uncaught exceptions with the same output as caught exceptions. The below shows the code I used to compare the differences in the exception log. I would appreciate help on working out the correct way to achieve this.
import sys, traceback
from loguru import logger
def divide(a, b):
return a/b
def handle_exception(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
exception = sys.exc_info()
logger.opt(exception=exception).exception("Uncaught Exception")
sys.excepthook = handle_exception
print("*************************************************************")
print("*********** Caught Exception *************")
print("*************************************************************")
try:
divide(2,0)
except:
logger.exception("Caught Exception")
print("*************************************************************")
print("********** Uncaught Exception ************")
print("*************************************************************")
divide(2,0)
Output

I cannot work out how to log uncaught exceptions with the same output as caught exceptions. The below shows the code I used to compare the differences in the exception log. I would appreciate help on working out the correct way to achieve this.
Output
