行号未在错误语句中正确显示 [英] line number not showing correctly in error statement

查看:107
本文介绍了行号未在错误语句中正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim st As StackTrace = New StackTrace(ex, True)
Dim sf As StackFrame = st.GetFrame(st.FrameCount - 1)
Console.WriteLine( sf.GetFileLineNumber())



我在捕获中使用了上面的代码行来显示错误发生时的行号,它显示的是行号,但不是导致错误的行的确切行号.任何想法请帮助



I used the above line of codes in the catch to show the line number when the error happens.Its showing a line number but its not exact line number of the line that cause the error. Any ideas please help

推荐答案

不要做这些奇怪的事情.只需使用Console.WriteLine(ex.StackTrace).
Don''t do such weird things. Just use a Console.WriteLine(ex.StackTrace).


如果您谈论的是Release版本,则行号毫无意义,因为优化可能会重新编写您的代码.

解决此问题的唯一方法是编译并使用该应用程序的Debug版本,但不建议这样做.
If you''re talking about a Release build, line numbers are meaningless as optimizations may have re-written your code.

The only way around this is to compile and use a Debug version of the app, which is not recommended by the way.


这篇关于行号未在错误语句中正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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