Proper way to handle errors in a module
Ethan Furman
ethan at stoneleaf.us
Thu May 12 16:40:44 EDT 2011
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.
class HelloError(Exception):
"custom exception"
and that's all you need. You can override __init__ to add your own
attributes, etc, if you need to.
~Ethan~
More information about the Python-list
mailing list