Proper way to handle errors in a module

MRAB python at mrabarnett.plus.com
Thu May 12 16:26:55 EDT 2011


On 12/05/2011 21:12, Andrew Berg wrote:
> On 2011.05.12 02:25 PM, MRAB wrote:
>> You can raise an exception wherever you like! :-)
> If I raise an exception that isn't a built-in exception, I get something
> like "NameError: name 'HelloError' is not defined". I don't know how to
> define the exception.

Define it as a subclass of Exception:

     class UnknownBirdError(Exception):
         pass



More information about the Python-list mailing list