发布后获取Exception的行号... [英] Get Line number of Exception after release...

查看:66
本文介绍了发布后获取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中获取错误行号 [ ^ ]


这篇关于发布后获取Exception的行号...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆