I am working on a piece of FastAPI app code that (already) has some exception handling, where handlers receive exceptions as function arguments, some exceptions are converted into other exceptions and then are passed on to other handler functions. My task is to log them, and I would like to be able to keep all the stactrace, including for those exceptions that resulted from converting other exceptions. However, when return MyNewException(old_exc.args)
is called, all the stacktrace from the first exception is lost.
I know that you can append to the stactrace if you raise MyNewException(old_exc.args) from old_exc
, but here there’s no raising, only passing exceptions raised and caught elsewhere.
Is there a way I can incorporate the stacktrace from the original exceptions in my situation?