473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird problem with exception constructor

Hello all,

I have a custom Exception inherited class with the following
constructor. I added the IIf call because the Parameters() value might
be null. But somehow I keep getting an ArgumentNullExc eption on
String.Format: 'Value cannot be null. Parameter name: args'.
If I replace this FalsePart of IIf with a random string like "hello
world", nothing is wrong, the correct part (TruePart) is used and I
get no exception.
It looks like the String.Format is executed anyway, also when the IIf
returns TruePart.

Any clues?

Regards,

Freek Versteijn
Public Sub New(ByVal ExceptionID As Integer, ByVal Parameters() As
Object, ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(IIf( Parameters Is Nothing, Message,
String.Format(M essage, Parameters)) & " (ExceptionID=" & ExceptionID &
")", InnerException)
FExceptionID = ExceptionID
FParameters = New Collection
End Sub
Nov 20 '05 #1
3 1100
Hi,

Make more than one version of the new procedure. Make one version
without the parameters option.

Public Sub New(ByVal ExceptionID As Integer, ByVal Parameters() As
Object, ByVal Message As String, ByVal InnerException As Exception)

MyBase.New(Stri ng.Format(Messa ge, Parameters) & " (ExceptionID="
& ExceptionID & ")", InnerException)
FExceptionId = ExceptionID
FParameters = New Collection
End Sub

Public Sub New(ByVal ExceptionID As Integer, ByVal Message As
String, ByVal InnerException As Exception)

MyBase.New(Mess age & " (ExceptionID=" & ExceptionID & ")",
InnerException)
FExceptionId = ExceptionID
FParameters = New Collection
End Sub

Ken
------------------

"Versteijn" <ve*******@538m ail.nl> wrote in message
news:4d******** *************** ***@posting.goo gle.com:
Hello all,

I have a custom Exception inherited class with the following
constructor. I added the IIf call because the Parameters() value might
be null. But somehow I keep getting an ArgumentNullExc eption on
String.Format: 'Value cannot be null. Parameter name: args'.
If I replace this FalsePart of IIf with a random string like "hello
world", nothing is wrong, the correct part (TruePart) is used and I
get no exception.
It looks like the String.Format is executed anyway, also when the IIf
returns TruePart.

Any clues?

Regards,

Freek Versteijn
Public Sub New(ByVal ExceptionID As Integer, ByVal Parameters() As
Object, ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(IIf( Parameters Is Nothing, Message,
String.Format(M essage, Parameters)) & " (ExceptionID=" & ExceptionID &
")", InnerException)
FExceptionID = ExceptionID
FParameters = New Collection
End Sub


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.0 - Release Date: 6/12/2004
Nov 20 '05 #2
Versteijn,
As Ken stated overload the constructor & make two versions.
It looks like the String.Format is executed anyway, also when the IIf
returns TruePart.

Any clues? The reason for the exception is that IIf is a function! Both the true part &
false part are always evaluated! All three parameters are passed to the IIf
function which then returns one of the two values.

Hope this helps
Jay

"Versteijn" <ve*******@538m ail.nl> wrote in message
news:4d******** *************** ***@posting.goo gle.com... Hello all,

I have a custom Exception inherited class with the following
constructor. I added the IIf call because the Parameters() value might
be null. But somehow I keep getting an ArgumentNullExc eption on
String.Format: 'Value cannot be null. Parameter name: args'.
If I replace this FalsePart of IIf with a random string like "hello
world", nothing is wrong, the correct part (TruePart) is used and I
get no exception.
It looks like the String.Format is executed anyway, also when the IIf
returns TruePart.

Any clues?

Regards,

Freek Versteijn
Public Sub New(ByVal ExceptionID As Integer, ByVal Parameters() As
Object, ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(IIf( Parameters Is Nothing, Message,
String.Format(M essage, Parameters)) & " (ExceptionID=" & ExceptionID &
")", InnerException)
FExceptionID = ExceptionID
FParameters = New Collection
End Sub

Nov 20 '05 #3
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:<Om******* *******@tk2msft ngp13.phx.gbl>. ..
Versteijn,
As Ken stated overload the constructor & make two versions.
It looks like the String.Format is executed anyway, also when the IIf
returns TruePart.

Any clues?

The reason for the exception is that IIf is a function! Both the true part &
false part are always evaluated! All three parameters are passed to the IIf
function which then returns one of the two values.

Hope this helps
Jay


DOH! It must have been very very late. Your're right. This is
problably the most stupid problem I have ever had.. Shame:(

Regards,

Freek Versteijn
Nov 20 '05 #4

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

Similar topics

2
2746
by: Scott Reynolds | last post by:
I am having a problem exposing a class inherited from the collection base class as a webservice. If I expose the collection on a web page all works well and I am very happy. However when I try and expose this via a web service I get a weird error saying that the dll could not be found. The specific error is: I can't figure it out. I thought it was to do with reflection but I am able to load and view the webservice definition which...
4
1740
by: JSheble | last post by:
If an exception occurs or is thrown in my constructor, what does the constructor actually return? A null?
3
3409
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is to be supplied to the exception constructor, the default constructor should
8
2215
by: nickyeng | last post by:
I have written 3 files, i dont know whether i do it correctly or wrongly but somehow it compiled well and can run. My simple aim is to display the terrain.txt file into the terrain array, and then display terrain into screen. I can't display the whitespace characters from terrain.txt file to screen. and It display "weird"( the red color part). http://i19.photobucket.com/albums/b171/NickyEng/display.jpg I tried searching one line by...
4
2245
by: sundarvenkata | last post by:
Hi All, I wanted to develop a WPF application to capture the output of a command line program and display it in a GUI. However I get a weird error in the following code: System.Diagnostics.Process pfadminProc = new System.Diagnostics.Process(); pfadminProc.StartInfo = new
4
2916
by: Sunil Varma | last post by:
Hi, Here is a piece of code where the constructor throws an exception. class A { int n; public: A() try{
6
1175
by: Joel Koltner | last post by:
I have a generic (do nothing) exception class that's coded like this: class MyError(exceptions.Exception): def __init__(self,args=None): self.args = args When I attempt to raise this exception via 'raise MyError' I get an exception within the MyError constructor __init__ as follows: Traceback (most recent call last):
5
1552
by: Vijay | last post by:
Hi All, I am not able to figure out what exactly happening in below code. what is control flow. Can anyone clear my confusion? Code: class A { public: A(){cout<<"In Constructor\n";}
6
1398
by: Lucas Kanebley Tavares | last post by:
Hello all, I have a templatized class which has an attribute as: "T *data", all constructors initialize it to zero, and then allocate memory for the array (and that IS done correctly, I've checked). What I find it strange, is that at one point I have to reallocate the data, but if I put this in my operator= overload: if (data != 0) delete data; //mem leak here
0
9715
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
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
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
10353
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
10356
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
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
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...
0
6869
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();...
1
4314
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.