Relative Content

Tag Archive for pythonexception

Python: init exception from another (like raise … from but with no raise)

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.