假设在一个程序的所有类的各方法属性等等中都没有加异常处理,现在想知道如何能获取引起该程序报错时的类名以及该类的方法名(不需要知道是什么错误类型)?
目前我知道用以下方法可以得到我想得到的
try{}catch(Exception ){Console.WriteLine(ex.Source);}可是工作量太大了,100多个类,每个类有那么多方法,不想一个一个的去做,现在请教大家有没有好的办法?
目前我知道用以下方法可以得到我想得到的
try{}catch(Exception ){Console.WriteLine(ex.Source);}可是工作量太大了,100多个类,每个类有那么多方法,不想一个一个的去做,现在请教大家有没有好的办法?
{
// Create a StackTrace that captures
// filename, line number and column
// information, for the current thread.
StackTrace st = new StackTrace(true);
for(int i =0; i< st.FrameCount; i++ )
{
// High up the call stack, there is only one stack frame
StackFrame sf = st.GetFrame(i);
Console.WriteLine("\nHigh Up the Call Stack, Method: {0}",
sf.GetMethod() ); Console.WriteLine( "High Up the Call Stack, Line Number: {0}",
sf.GetFileLineNumber());
}
}