473,786 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(':'.j oin([ex.__module__, ex.__class__.__ name__]))
This works just fine for user-defined exceptions like:
>>class UserException(E xception):
pass
>>uex = UserException()
print ':'.join([uex.__module__, uex.__class__._ _name__]) # __main__.UserEx ception
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:Exce ption
print ':'.join([uex.__class__._ _module__, uex.__class__._ _name__]) # __main__:NewExc eption
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 1192
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_an d_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
8980
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 it couldn't find that font it used the next on the list and so on. If it couldn't find any on the list, prior to the last it would use the last - which, as you can see is sans-serif here. When I use the following style I get what I think is...
6
907
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 in the file change very rarely, so I would like to keep it in a single copy in-memory if that's possible.
4
1604
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 inform. Thanks, Yasaswi
90
4419
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 immutable instances? -- \ "Love is the triumph of imagination over intelligence." -- |
16
1558
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 sans for <hx>. Regards. --
18
5160
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 relate to the childrem ?
4
1990
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
1231
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 & getting quite tired (:huh: ) of it. So I think it's time to call some help. I hope there must be some solution. I NEED it. Well actually what I need ? I need to have some class/object which create some OleObjects (images and buttons) runtime....
5
1476
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 words, I can do this: .... pass .... 33
0
9655
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
10363
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
10169
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
10110
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
8993
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
7517
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...
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.