473,832 Members | 2,090 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 1101
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
2747
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
3410
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
2217
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
1176
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
1556
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
1400
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
9795
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
9642
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
10780
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
10498
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...
0
6951
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
5623
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...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
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
3
3077
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.