473,289 Members | 1,756 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,289 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 1176
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...

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.