Exception Handling Practices / Patterns

snarf frank.ruiz at gmail.com
Sat Aug 24 01:25:55 EDT 2013


Greetings,

As I tread through my journey of OO I am trying to determine if there is a good approach for exception handling within classes.

>From my readings and gatherings - it seems I have found a common theme, but I am trying to solicit from the experts.

Here is what I have found (I may be restating the obvious so please forgive me in advance):

* Seems like exception handing within Classes is largely avoided and is typically only used when calling external libraries.
* Try/Except type statements seem to be used more within modules, main functions, wrapper scripts.
* Classes should be coded in a way that exceptions 
* Better to never write your own exceptions (unless you absolutely have to).
* Using Exception is typically a bad. More specific the better.
* Exceptions should never fail silently. (Should exceptions always be logged?)

Best site I have found for exceptions (hopefully this helps someone):
* http://c2.com/cgi/wiki?ExceptionPatterns


I'd be interested in hearing others thoughts on this topic with regards to best practices for when to use exceptions, and when to avoid using exceptions.

Thank you in advance!



More information about the Python-list mailing list