I just got the strangest error. I have exception code that catches a
null reference exception:
catch (NullReferenceException ex) { ... }
The handling code does nothing but print out data from within the
object, ex. So, nothing is changed. And I've found that the
exception object, ex, ITSELF is null!
So, by accessing it to print its innards, it throws another
NullReferenceException (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerException is what
throws the null reference, since ex is null.
Strange. I'll see if I can replicate this, and nail it down.
Zytan 7 1956
Strange. I'll see if I can replicate this, and nail it down.
I think the null reference was from ex.InnerException being null. And
I was trying to print ex.InnerException.Message. However, what threw
me off was that viewing ex in the debugger shows:
ex {"Object reference not set to an instance of an object."}
System.NullReferenceException
This made me believe ex was null. (Of course, it would show "null" if
it was null.) But, if the object referenece in not set to an instance
of an object, then WTH is it set to? In the debugger, under ex, it
shows no methods, just "base". Under that, "base" again. Finally,
under that, it shows some methods.
Zytan
But, if the object referenece in not set to an instance
of an object, then WTH is it set to?
LOL! It's telling me that the exception IS that an object was
referenced that was null (not set to an instance of an object).
Zytan
"Zytan" <zy**********@yahoo.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
>Strange. I'll see if I can replicate this, and nail it down.
I think the null reference was from ex.InnerException being null. And
I was trying to print ex.InnerException.Message. However, what threw
me off was that viewing ex in the debugger shows:
ex {"Object reference not set to an instance of an object."}
System.NullReferenceException
This made me believe ex was null. (Of course, it would show "null" if
it was null.) But, if the object referenece in not set to an instance
of an object, then WTH is it set to? In the debugger, under ex, it
shows no methods, just "base". Under that, "base" again. Finally,
under that, it shows some methods.
The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed
an instance of NullReferenceException, with InnerException=null and
Message="Object reference not set to an instance of an object."
>
Zytan
"Zytan" <zy**********@yahoo.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
>I just got the strangest error. I have exception code that catches a
null reference exception:
catch (NullReferenceException ex) { ... }
The handling code does nothing but print out data from within the
object, ex. So, nothing is changed. And I've found that the
exception object, ex, ITSELF is null!
So, by accessing it to print its innards, it throws another
NullReferenceException (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerException is what
throws the null reference, since ex is null.
Strange. I'll see if I can replicate this, and nail it down.
ex isn't null, InnerException is.
The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed
an instance of NullReferenceException, with InnerException=null and
Message="Object reference not set to an instance of an object."
Yup, thanks Ben, I figured it out somewhat myself. But, yeah, it's
nice to know that ToString() returns Message.
Zytan
So, by accessing it to print its innards, it throws another
NullReferenceException (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerException is what
throws the null reference, since ex is null.
ex isn't null, InnerException is.
Indeed.
Zytan
"Zytan" <zy**********@yahoo.comwrote in message
news:11*********************@n76g2000hsh.googlegro ups.com...
>The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed an instance of NullReferenceException, with InnerException=null and Message="Object reference not set to an instance of an object."
Yup, thanks Ben, I figured it out somewhat myself. But, yeah, it's
nice to know that ToString() returns Message.
Peeking at mscorlib with the insanely useful .NET Reflector
( http://www.aisto.com/roeder/dotnet/), we can see exactly how
Exception.ToString() works:
public override string ToString()
{
string text2;
string message = this.Message;
if (this._className == null)
{
this._className = this.GetClassName();
}
if ((message == null) || (message.Length <= 0))
{
text2 = this._className;
}
else
{
text2 = this._className + ": " + message;
}
if (this._innerException != null)
{
text2 = text2 + " ---" + this._innerException.ToString() +
Environment.NewLine + " " +
Environment.GetResourceString("Exception_EndOfInne rExceptionStack");
}
if (this.StackTrace != null)
{
text2 = text2 + Environment.NewLine + this.StackTrace;
}
return text2;
}
>
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TT (Tom Tempelaere) |
last post by:
Hi,
Once in a while my application throws an NullReferenceException at startup,
however it appears to be occurring in an unknown module. If I debug it and
ask to 'break', then there is no source...
|
by: Matthias Kwiedor |
last post by:
Hi!
I want to create a WebBrowser Control at runtime. So i ported the "at
start creation" of the Control to a new routine.
Everything works fine, but i implement the BeforeNavigateFix and a...
|
by: Eduard Ralph |
last post by:
Hi,
I have a weird exception happening when calling the new operator. I'm
not sure if this is the intended reaction to the situation or is
actually a problem I've got. In any case a different...
|
by: Bob |
last post by:
I have several simple user controls (e.g. header, footer) that have static
content so I thought it would be a good idea to turn on the ouput cache. So
I added <%@ OutputCache Duration="600"...
|
by: theta |
last post by:
Hi everyone,
I'm a newbie .NET developer with vb6 experience. I was toying myself with
the Howl open source library for Zeroconf networks and I stumbled across an
exception I can't quite figure...
|
by: theta |
last post by:
Hi everyone. I'm a .NET newbie and I have a problem calling DLL functions
from vb .net.
I'm trying to access Howl's Rendezvous.dll
(www.porchdogsoft.com/products/howl/) from managed code. I was...
|
by: Ryan Liu |
last post by:
I have a program works fine in .NET 1.1 and just recompiled in .NET 2.0
without any code change. Compiles OK, but there is an exeception when
execute it.
Then I remove PK, it works all fine...
|
by: Sagar |
last post by:
Hi.
I am working on a project to migrate a web application from 1.1 to 2.0
Within in the DAL of the application, there is a call to below
function that builds a command object for later use.
...
|
by: puzzlecracker |
last post by:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an ob
ject.
Here is where I get this:
public void Foo(){
ArrayList list=new ArrayList();...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |