如何使用StackTrace在vb.net中返回错误行号 [英] How to use Stacktrace to return Error Line Number in vb.net

查看:194
本文介绍了如何使用StackTrace在vb.net中返回错误行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些将返回错误行号的错误捕获方法。我们有一个中止电子邮件,当进程中止时,我们发送了一个中断邮件,这些邮件给了我们 err.number err.description ,但我想知道实际出错的地方。

I am trying to create some sort of error catching method that will return the error line number. We have an abort email that is sent out when a process aborts that gives us the err.number and err.description but I would like to know where is actually errors out.

我知道您可以执行以下操作:

I know you can do the following:

1: code here
2: code here
3: code here

等。并使用ERL来获取数字,但是像这样输入每一行将是乏味的。

etc. and use ERL to get the number but it would be tedious to type each line out like that.

有没有办法自动执行此操作或更容易使用Stacktrace?如果StackTrace更好,请给我一个例子?

Is there either a way to automatically do this or would it be easier to use Stacktrace? If Stacktrace is better could you please show me an example?

推荐答案

在异常堆栈跟踪中生成行号是一个内置的功能为CLR。然而,您必须提供将代码地址映射到行号所需的信息。切换到项目的Release配置。项目+属性,编译选项卡,高级编译选项。将生成调试信息设置从pdb-only更改为完全。部署.pdb文件以及您的程序。

Generating line numbers in exception stack traces is a built-in feature for the CLR. You do however have to provide the information it needs to map a code address to a line number. Switch to the Release configuration of your project. Project + Properties, Compile tab, Advanced Compile Options. Change the "Generate debug info" setting from pdb-only to Full. Deploy the .pdb files along with your program.

请注意,您获得的行号总是一个估计值,所以不要盲目信任你看到的内容。由于抖动优化器内嵌方法和其他方式移动代码,使程序运行速度更快,所以映射是不完美的。

Beware that the line number you get is always an estimate so do not blindly trust what you see. The mapping is imperfect due to the jitter optimizer inlining methods and otherwise moving code around to make the program run faster.

这篇关于如何使用StackTrace在vb.net中返回错误行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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