Yes, there are framework classes that will give you the Call Stack information at a particular point.
[C#]
public static void TraceExceptionCatched(Exception e)
{
StackTrace st = new StackTrace(1, true);
StackFrame sf = st.GetFrame(StackTrace.METHODS_TO_SKIP);
if (sf != null)
{
MethodBase mb = sf.GetMethod();
Trace.WriteLine(e.ToString());
StringBuilder sb = new StringBuilder();
sb.Append('catched in File ');
sb.Append(sf.GetFileName());
sb.Append(', line ');
sb.Append(sf.GetFileLineNumber());
Trace.WriteLine(sb.ToString());
sb = new StringBuilder();
sb.Append('in method ');
sb.Append(mb.ReflectedType.Name);
sb.Append('.');
sb.Append(mb.Name);
sb.Append('(');
bool first = true;
foreach (ParameterInfo pi in mb.GetParameters())
{
if (!first)
sb.Append(', ');
first = false;
sb.Append(pi.ParameterType.Name);
sb.Append(' ');
sb.Append(pi.Name);
}
sb.Append(');');
Trace.WriteLine(sb.ToString());
}
}
You could then call this method from the Catch portion of a try/catch block.
Share with