473,405 Members | 2,272 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,405 software developers and data experts.

Instances of BaseException and family don't provide __module__?

I have started working on a new project using ZSI and perhaps one can
argue this is a bug in ZSI, but I found it odd. The ZSI dispatcher
needs to catch all exceptions and pass that over to the client; in
doing so, it passes along the name of the exception that occurred so
that the client can know more than just "it failed." Anyways, I am
getting off the point, the mechanics of this code in ZSI goes more or
less like this:
>>try:
doSomething()
except Exception, ex:
sendFault(':'.join([ex.__module__, ex.__class__.__name__]))
This works just fine for user-defined exceptions like:
>>class UserException(Exception):
pass
>>uex = UserException()
print ':'.join([uex.__module__, uex.__class__.__name__]) # __main__.UserException
But falls on its face with built-in exceptions:
>>ex = Exception()
print ':'.join([ex.__module__, ex.__class__.__name__]) # AttributeError!
, because the built-in exception instances don't have the __module__
attribute (as of 2.5). The only way this works in 2.4 as well as 2.5
is to do:
>>print ':'.join([ex.__class__.__module__, ex.__class__.__name__]) # exceptions:Exception
print ':'.join([uex.__class__.__module__, uex.__class__.__name__]) # __main__:NewException
But this is a bit obscure and I don't understand why user-defined
exception instances should have a different set of attributes than the
built-in exception instances. As well as this is a change from 2.4-
>2.5 that breaks existing code for no apparent reason. This smells
like it was an overlooked mistake and not a feature. I am tempted to
open a bug against python for it, but I didn't know if someone could
give a rational reason why that attribute is missing?

Thanks,
-Scott

Nov 3 '07 #1
1 1181
On Fri, 02 Nov 2007 19:36:05 -0700, Scott Dial wrote:
I have started working on a new project using ZSI and perhaps one can
argue this is a bug in ZSI, but I found it odd. The ZSI dispatcher needs
to catch all exceptions and pass that over to the client; in doing so,
it passes along the name of the exception that occurred so that the
client can know more than just "it failed."
I have no opinion on whether the problem you report is a bug in Python or
ZSI or not, but I'd suggest that passing along the name of the exception
is not the right way to go about it.

The right way is to pass along the exception itself:

try:
doSomething()
except Exception, ex:
sendFault(ex)
report_error_and_continue()

(Always assuming you want to continue.)

That gives the caller access to as much or as little of the exception as
it needs.
--
Steven.
Nov 3 '07 #2

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

Similar topics

9
by: Zenobia | last post by:
Is there a problem with the CSS font-family property with IE6 - or is it my understanding of the font-family property? I was under the impression that the browser tried to use the first font. If...
6
by: Angelos Karantzalis | last post by:
Hi y'all ... I'm a bit puzzled here about .NET class instancing under COM+ Issue 1: I've a COM+ component, let's call it ... COMDbWrapper that initializes itself from an xml file. The data...
4
by: Yasaswi Pulavarti | last post by:
After running db2setup for the first time, what is the best way to create additional instances on the same host? Is running db2setup again better or running the db2icrt CLI command better? Please...
90
by: Ben Finney | last post by:
Howdy all, How can a (user-defined) class ensure that its instances are immutable, like an int or a tuple, without inheriting from those types? What caveats should be observed in making...
16
by: Nije Nego | last post by:
What is you favourite font family choice for pages with predominant text content? Which one is the most readable, with regards to body text <pand what for <h1>? I tend to use serif for <pand...
18
by: Cliff Chapin | last post by:
I want to create a Family database some of these "families " are single fathers with children some are single women with children they will be assigned Rooms /w children. what would be the best to...
4
by: =?Utf-8?B?TWFyc2hhbGw=?= | last post by:
In the sentence, "Our efforts in serving "The Pearson Family" span several years," do you capitalize "The" and "Family"?
0
by: bettatronic | last post by:
The goal : to have class which is able to add some OLE objects on the sheet runtime. Instances of the class must be accessible from any public/private module. Okay, I've experimented for so long &...
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.