473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exception message output problem

I am baffled about why my exception messages are not displaying
properly.

I have a class that represents physical scalars with units. If I type
>>3 * s + 4 * m
I should get something like this:

scalar.Inconsis tentUnits: 3 s, 4 m

to show that seconds cannot be added to meters. Instead, the message
is broken up into individual characters, like this:

scalar.Inconsis tentUnits: ('3', ' ', 's', ',', ' ', '4', ' ', 'm')

This worked correctly for months, so I don't understand what went
wrong. I am using version 2.5.1 on a Dell workstation with Red Hat
Enterprise WS Linux.

As far as I can tell, I am doing everything "by the book." Here is my
exception class:

class InconsistentUni ts(Exception):
def __init__(self, args=""): self.args = args

and here is my instantiation of it:

raise scalar.Inconsis tentUnits, str(self) + ", " + str(other)

I've tried various little changes, but nothing seems to make any
difference. Has anyone else noticed this sort of behavior? Thanks.

By the way, my scalar class is available for free from http://RussP.us/scalar.htm
.. A complete user guide is available. Check it out. I think you'll
like it.

Dec 21 '07
11 1679
On Dec 22, 5:34 am, Fredrik Lundh <fred...@python ware.comwrote:
Russ P. wrote:
Actually, the parens aren't needed, so this works too:
def __init__(self, args=""): self.args = args,
The trailing comma wasn't necessary a while back (pre 2.5?), so
something in Python must have changed. I'd say that it looks a bit
cleaner without the trailing comma, so maybe whatever changed should
get changed back.

as the name implies, "args" is supposed to be a sequence, and is stored
internally as a tuple. if something has changed, it's probably that 2.5
enforces this behaviour via a property.

to fix your code, just replace your own __init__ method with a "pass",
and leave the initialization to the Exception class itself.
That works. And because it is the simplest solution here, I'd say it's
the "correct" solution. Thanks.

Dec 23 '07 #11
Lie <Li******@gmail .comwrote:

# Python have an odd (read: broken) singleton implementation
# single member tuple must have a comma behind it
Otherwise (1+2)+(3+4) would evaluate to (3, 7) instead of 10.

Florian
--
<http://www.florian-diesch.de/>
-----------------------------------------------------------------------
** Hi! I'm a signature virus! Copy me into your signature, please! **
-----------------------------------------------------------------------
Dec 23 '07 #12

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

Similar topics

1
4915
by: Newsgroup - Ann | last post by:
The fstream is supposed to be a replacement of the stdio.h and the exception is supposed to be a replacement of the return error code. So how do I replace my old codes of the style: if (output = fopen(...) == NULL) { perror("..."); exit(1); } by the C++ style? The only thing I can do now is like
3
2952
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
19
3210
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE and Everyone, with Full Control to see if it's a permissions problem. The project is hosted in a Windows 2003 Server and developed from PCs in a domain, developing with Visual Studio 2005 Beta 1. -- Regards,
4
2249
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
7
2692
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
5
5739
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the exception occurred?
5
1380
by: Sridhar | last post by:
Hi, I have created a web application. I have a data access dll to interact with database. I added this dll as a reference to the web application. Now let's say if I am calling a function in data access and if it throws exception (like cannot find stored procedure), how do I retrieve that exception message back in the web form? In the client, I am able to catch the exception, but the message I am getting is "Object reference not set to an...
2
24515
by: Abubakar | last post by:
Hi all, I'm writing an app in vc++ 2k5 (all native/unmanaged). This application does a lot of multithreading and socket programming. Its been months since I'm developing this application, at this point a lot of it is working just fine, my app running fine, threads r being made and destroyed, memory is being dynamically allocated at God knows how many places and ,hopefully, getting deallocated as well. Its just by coincedence I happened...
12
2175
by: josh | last post by:
Hi I have this code: class Exception : public exception { public: Exception(string m="exception!") : msg(m) {} ~Exception() throw() {} const char* what() { return msg.c_str(); } private:
3
3467
by: Miro | last post by:
I cant seem to find an example on how to do something, ( vb2005.express ) i have a Try ListeningSerialPort.Open() TestText.Enabled = True Catch ex As Exception 'Debug.WriteLine(ex.Message) End Try
0
8683
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
9031
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
8902
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
7740
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
6528
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
5862
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
4372
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...
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.