如何获得异常错误行没有? [英] How to get Exception Error Exactly Line No ?

查看:64
本文介绍了如何获得异常错误行没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写的是以下代码的例外行号



string errorLine;

StackTrace st = new StackTrace(0,true);

StackFrame sf = new StackFrame();

sf = st.GetFrame(0);

errorLine = sf.GetFileLineNumber()。ToString();



但是,我没有得到完全异常行号。不同的行号来了

解决方案

尝试调试代码,你就可以获得引发异常的行。


< blockquote>试试这个



 尝试 
{
throw new 异常();
}
catch (例外情况)
{

var ExceptionMsg = new StackTrace(例如, true );

var LineException = ExceptionMsg.GetFrame( 0 );

var line = LineException.GetFileLineNumber();
}





更多信息



如何使用try-catch获取错误行代码 [ ^ ] < br $> b $ b

如何使用try-catch获取错误代码行数 [ ^ ]


行号仅存在于Debug编译的.EXE中。由于Release配置的构建已启用优化,因此不再可能执行可执行代码和源代码之间的映射。编译器会根据需要重写代码!


Hi,
I am written below the code for exception Line number

string errorLine;
StackTrace st = new StackTrace(0, true);
StackFrame sf = new StackFrame();
sf = st.GetFrame(0);
errorLine = sf.GetFileLineNumber().ToString();

But, I am not getting exactly exception line no. different line no is came

解决方案

try to debug the code and you will be able to get the line which is raising exception.


Try this

try
{
    throw new Exception();
}
catch (Exception ex)
{
    
    var ExceptionMsg= new StackTrace(ex, true);
    
    var LineException= ExceptionMsg.GetFrame(0);
    
    var line = LineException.GetFileLineNumber();
}



for more info

How to get error line number of code using try-catch[^]

How to get error line number of code using try-catch[^]


Line numbers only exist in a Debug compiled .EXE. Since a Release configured build has optimizations turned on the mapping between the executable code and your source code is no longer possible. The compiler is rewriting your code as it sees fit!


这篇关于如何获得异常错误行没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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