Re-raising a RuntimeError - good practice?

Peter Cacioppi peter.cacioppi at gmail.com
Fri Oct 25 03:44:36 EDT 2013


I'm surprised no-one is mentioning what seems the obvious pattern here - exception wrapping.

So you define your exception class as containing the root exception.

Then your specific job routines wrap the exceptions they encounter in your personal exception class. This is where you go add in specific information re: the circumstances under which the exception occurred. 

Then you throw your exception, which is captured at the appropriate level, and logged appropriately.

The nice thing here is that you to tend to write all the exception logging in one place, instead of scattered all around.

Your code looks very close to this pattern.  Just raise an exception that can wrap the low level exception.



More information about the Python-list mailing list