473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Superclass for Errors?

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?

Dec 27 '06 #1
3 1821
"tac-tics" <ta*******@gmail.comwrites:
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.
See http://rgruet.free.fr/PQR25/PQR2.5.html#BuiltInExc

I would guess you're looking for StandardError.

--
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk | Visit us at: http://www.gmta.info
Dec 27 '06 #2
On Wed, 2006-12-27 at 12:13 -0800, tac-tics wrote:
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.
Yes, that superclass is Exception:
>>for klass in (TypeError, NameError, RuntimeError, AttributeError):
.... print klass, issubclass(klass, Exception)
....
exceptions.TypeError True
exceptions.NameError True
exceptions.RuntimeError True
exceptions.AttributeError True

Have you encountered many TypeError, NameError, RuntimeError or
AttributeError exceptions that "except Exception" by itself failed to
catch?

-Carsten
Dec 27 '06 #3
At Wednesday 27/12/2006 17:13, tac-tics wrote:
>For exceptions, I can simply use a catch-all except statement like:

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

Normally, I could simply use a regular

except:
....

but then I don't have access to the error message.
Other people already said that all builtin exceptions are derived
from Exception. So using except Exception: xxx, you catch all of
them. What's left:
- string exceptions: deprecated long time ago, but you might
encounter them in old code.
- other classes not derived from Exception: still legal, probablly
not on future Python versions.
If you really have to catch any kind of exception, use a bare except
clause; you always can retrieve the exception details using
sys.exc_info()
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first...
2
by: rh0dium | last post by:
Hi all, Still a newbie but making some headway. So I have a file structure like this.. top/ --modules/ ----metrics.py --metrix/ ----uptime.py
3
by: chriss | last post by:
Hi, environment: Python 2.4, GNU/Linux, kernel 2.6.12.2 having subclassed 'Exception' I'm trying to call the initialiser __init__(...) of the superclass Exception with 'super(..).__init__(..)'...
2
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass'...
1
by: Nishith Prabhakar | last post by:
Hi, I have a class which inherits from a template (vector). This class is defined in the header file as below. Output.h class _DLL_RESPONSE_SERVER Output : public vector<SingleOutput> {...
1
by: Florian Lindner | last post by:
Hello, I try to call the superclass of the ConfigParser object: class CustomizedConfParser(ConfigParser.SafeConfigParser): def get(self, section, attribute): try: return...
4
by: ingoweiss | last post by:
Hi, I am having trouble passing parameters of a Javascript subclass constructor through to it's superclass constructor. I am trying all sorts of things, including the below, but nothing...
1
by: shivapadma | last post by:
1..In java we can refer superclass constructor by super()keyword,but Where as in c++ how can we refer to that???. In java the following code is used for referring superclass...
2
by: Mark Brading | last post by:
Hi all, I am trying to declare a Map object with an abstract superclass (TableFields_v2) object as follows:- private Map<Integer, TableFields_v2> elementList; When I come to create the object...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.