yesman
yesman

Reputation: 7829

Can't access Exception property

I am catching an ArgumentException, of which I want a specific property. When I put a breakpoint on the code where the ArgumentException is caught, I see that it has an ErrorMessage property:

enter image description here

But trying to access it gives this result:

enter image description here

What's going on here?

Upvotes: 1

Views: 1086

Answers (2)

Alberto Chiesa
Alberto Chiesa

Reputation: 7350

The explanation is that the first screenshot is NOT a stamp of the exceptions internals. An ArgumentException has no "ArgumentException" message. This is absolutely sure.

What is the first screenshot referring to? I really don't know, but it seems some sort of service context, already updated with the relevant information.

What you are probably searching for, btw, is the Message property of the exception.

Upvotes: 0

jgauffin
jgauffin

Reputation: 101150

The problem is that in the first screenshot you display the HttpWebResponse or similar object, while in the second screenshot you are working with the actual exception.

Exceptions have a Message property and not an ErrorMessage. Change the second code to ex.Message and it will work.

Upvotes: 2

Related Questions