If I understand you correctly, do you want to throw an exception while maintaining stacktrace? So you have a call hierarchy:
error_handling_module
In your module_excepting_and_rethrowing you can do:
except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() raise NewException, exc_value, exc_traceback
In Python3, you can also:
except Exception as e: raise NewException from e
source share