Question about the Exception class

Georg Brandl g.brandl-nospam at gmx.net
Thu Jun 15 02:06:03 EDT 2006


Carl J. Van Arsdall wrote:
> So this is probably a fairly basic question, but help me out because I'm 
> just not lining things up and I'm somewhat new to the world of exception 
> handling.
> 
> What's the benefit to inheriting an exception from and of the available 
> parent exception classes?  Does one subclass have benefits over any 
> other?  Most of what I see involves making a new class and inheriting 
> from Exception so that one can have an exception class with a name of 
> their choosing.  If you didn't care about the name would there be any 
> benefit to making a subclass versus raising StandardError or something 
> else equally vanilla?  Are there any difference to library provided 
> exceptions other than their names?

Creating your own exception hierarchy and using it consistently can help
you debugging when an exception raised by Python itself occurs. Also, you
can customize your own exception objects (such as, add new instance
attributes).

Georg



More information about the Python-list mailing list