Shyju
Shyju

Reputation: 218732

How do I get specific details about an exception from a general Exception class object?

In ASP.NET,How can i know the Specific details about an exception (like What kind of Exception it is (FileNotFound /Arithmentc etc..) )from a General Exception class object

Upvotes: 0

Views: 238

Answers (2)

Oded
Oded

Reputation: 499002

If you need the full details (stack trace, names and such) from an exception object, use the overloaded ToString() on it. It gives quite a lot of information.

Upvotes: 1

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

You can use GetType() method to get the actual type of the exception instance.

If you are interested in some property of a specific type of exception and you're sure about the type, just cast the exception to the type and fetch the property value.

Alternatively, you can use reflection to interrogate the object and retrieve all of its properties.

Upvotes: 1

Related Questions