Superclass for Errors?

tac-tics tactics40 at gmail.com
Wed Dec 27 15:13:05 EST 2006


I have a program which has a GUI front-end which that runs a separate
thread to handle all the important stuff. However, if there is a
problem with the important stuff, I want the GUI to raise a MessageBox
alert to indicate this.

For exceptions, I can simply use a catch-all except statement like:

try:
    ...
except Exception, error:
    JOptionPane.showMessageDialog(self, "Error: %s" % error)

Only, I want it to catch Errors as well. Right now, I'm using:

try:
    ...
except (Exception, TypeError, NameError, RuntimeError, AttributeError),
error:
    JOptionPane.showMessageDialog(self, "Error: %s" % error)

I was wondering if there is a superclass for TypeError, NameError,
RuntimeError, AttributeError, etc.

Normally, I could simply use a regular

except:
    ....

but then I don't have access to the error message.

So what's the best solution to this problem?




More information about the Python-list mailing list