发布后获取Exception的行号...
问题描述:
我正在开发一个Windows应用程序。并且,我尝试在每个代码块中捕获...
它现在跟踪异常的classname,methodname。现在我想跟踪行号...
我该怎么做?是否会影响应用程序性能如果我使用PDB文件?
我可以使用这样的标志吗??
Hi,
I am developing a windows application. and, I have try catch in each and every code block...
It now traces classname, methodname of the exception. Now I want to trace the line number too...
How can I do it ? Will it affect the application perfomance If I use PDB files ??
Can I use a flag like this ??
public void function_name()
{
int linenum = 0 ;
try
{
somecodehere();
linenum++;
someothercodehere();
linenum++;
}
catch(Exception ex)
{
Console.WriteLine("Line Number: " + linennum);
}
}
答
如何到获取错误线数-的代码,使用-的try-catch [ ^ ]
希望它会有所帮助..
how-to-get-error-line-number-of-code-using-try-catch[^]
Hope it will help..
尝试以下解决方案:
Try Below Solution:
catch (Exception ex)
{
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
Console.WriteLine("Line: " + trace.GetFrame(0).GetFileLineNumber());
}
并在下面链接中提及:
在Vb.net中获取错误行号 [ ^ ]