在异常处理中显示行号 [英] Show line number in exception handling

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

问题描述

如何显示导致错误的行号,这是否可以通过 .NET 编译其 .exe 的方式实现?

How would one display what line number caused the error and is this even possible with the way that .NET compiles its .exes?

如果没有,Exception.Message 是否有一种自动方式来显示被淘汰的子?

If not is there an automated way for Exception.Message to display the sub that crapped out?

try
{
  int x = textbox1.Text;
}
catch(Exception ex)
{
     MessageBox.Show(ex.Message);
}

推荐答案

使用 ex.ToString() 获取完整的堆栈跟踪.

Use ex.ToString() to get the full stack trace.

即使在发布模式下,您也必须使用调试符号(.pdb 文件)进行编译,以获取行号(这是项目构建属性中的一个选项).

You must compile with debugging symbols (.pdb files), even in release mode, to get the line numbers (this is an option in the project build properties).

这篇关于在异常处理中显示行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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