473,763 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.sho wMessageDialog( 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.sho wMessageDialog( 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 1834
"tac-tics" <ta*******@gmai l.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.sho wMessageDialog( 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.sho wMessageDialog( 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.sho wMessageDialog( 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.sho wMessageDialog( 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(klas s, Exception)
....
exceptions.Type Error True
exceptions.Name Error True
exceptions.Runt imeError True
exceptions.Attr ibuteError 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.sho wMessageDialog( 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
2006
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 module (given an instance of the first class) without importing it. Example of what I'm looking for: <<<file spam.py>>> class Spam(object):
2
1186
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
5147
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__(..)' . However, trying to do so results in a 'TypeError: super() argument 1 must be type, not classobj'. Now, if I use 'Exception.__init__(..)' instad of super(..)... ,everything
2
3036
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' priviledged methods also. Do you know if this is possible ? In the following example, I create an ObjectA (variable a), an ObjectB which inherits ObjectA (variable b) and an ObjectC which inherits ObjectA (variable c1). The 'toString ()' method...
1
1277
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> { public:
1
2097
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 super(CustomizedConfParser, self).get(section, attribute) #
4
3900
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 worked so far. Thanks for any help!
1
2865
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 constructor.. class cal1 { private int a,b,c; public cal1(int i,int j) { a=i;
2
2378
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 element for the Map I want to be able to use a subclass of the superclass for the object; for example:- this.elementList = new HashMap<Integer, TableFields_v2_Year>(); Where TableFields_v2_Year is a subclass of TableFields_v2 However, Java won't...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.