Finding parameter values in an Exception

C

chris

I am sure I am overlooking something simple, but here goes. In the
global.asax file I have some code in the Application_Error method that
reads information out of the current exception and emails it to me. I
want to see what the parameter values are for the method throwing the
exception. I am using reflection to get the parameter metadata, but
this does not do me much good.

Exception ex = Server.GetLastError().GetBaseException();

MethodInfo mi =
(MethodInfo)MethodInfo.GetMethodFromHandle(ex.TargetSite.MethodHandle);

ParameterInfo[] parameters = mi.GetParameters();

Lets say the method throwing the exception has the following signature.
public void MyMethod(string foo, string bar)

The exception is thrown when the values are foo = "something" and bar =
"something else"

How do I find the values of foo and bar at runtime in Application_Error
method?

TIA,
Chris
 
D

Dave Sexton

Hi Chris,

You must pass the parameter values to a strong-Typed Exception class that
can support them.

In other words, the StackTrace doesn't save those values and by the time
Application_Error is called the values will probably have already been
collected by the GC so you must design your program to create diagnostics
information on a need-to-know basis.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top