473,320 Members | 1,858 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,320 software developers and data experts.

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 ArgumentNullException 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(Message, Parameters)) & " (ExceptionID=" & ExceptionID &
")", InnerException)
FExceptionID = ExceptionID
FParameters = New Collection
End Sub
Nov 20 '05 #1
3 1078
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(String.Format(Message, 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(Message & " (ExceptionID=" & ExceptionID & ")",
InnerException)
FExceptionId = ExceptionID
FParameters = New Collection
End Sub

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

"Versteijn" <ve*******@538mail.nl> wrote in message
news:4d**************************@posting.google.c om:
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 ArgumentNullException 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(Message, 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*******@538mail.nl> wrote in message
news:4d**************************@posting.google.c om... 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 ArgumentNullException 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(Message, 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**************@tk2msftngp13.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
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...
4
by: JSheble | last post by:
If an exception occurs or is thrown in my constructor, what does the constructor actually return? A null?
3
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...
8
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...
4
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: ...
4
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
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...
5
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
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...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.