User-defined exceptions from 2.6

J

Joan Miller

Which is the best way to create user-defined exceptions since that
*BaseException.message* is deprecated in Python 2.6 ?
 
S

Steven D'Aprano

Which is the best way to create user-defined exceptions since that
*BaseException.message* is deprecated in Python 2.6 ?


Inherit from an existing exception.

.... pass
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.MyValueException: value is impossible, try again


.... pass
....Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.GenericError: oops


Do you need anything more complicated?
 
J

Joan Miller

Inherit from an existing exception.


...     pass
...


Traceback (most recent call last):


...     pass
...>>> raise GenericError("oops")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.GenericError: oops

Do you need anything more complicated?
It's enought, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top