0

I'm doing some DB updates during my python application so I need to catch all exceptions (i.e. except without type or with general Exception type) to rollback DB
But I also need to re-raise the exception for parent functions in the call stack so they can do their clean up too.

I can re-raise the exception by wrapping them in Exception class but i need to preserve their type

How can I re-raise catched exception of any type preserving their type and data in python?

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Ariyan
  • 14,760
  • 31
  • 112
  • 175
  • 1
    You can simply do `except ExceptionType as e: #do stuff` and then `raise e` – Arne Nov 29 '17 at 11:33
  • 2
    Possible duplicate of [How to re-raise an exception in nested try/except blocks?](https://stackoverflow.com/questions/18188563/how-to-re-raise-an-exception-in-nested-try-except-blocks), [In Python, how do I inspect and then re-raise an exception while maintaining the original call stack?](https://stackoverflow.com/questions/12209450/in-python-how-do-i-inspect-and-then-re-raise-an-exception-while-maintaining-the) – Ilja Everilä Nov 29 '17 at 11:34

0 Answers0