C#MessageBox错误消息

Jim*_*ell 6 c# debugging error-handling messagebox

在我的应用程序中,我使用消息框来显示错误信息.

try
{
   // Something...
}
catch (SystemException ex)
{
   MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Run Code Online (Sandbox Code Playgroud)

起初这很好,但随着程序的增长,找到生成此错误的try-catch块变得越来越困难.有没有办法显示生成错误的代码行或函数?我使用的是Microsoft Visual C#2008 Express Edition.谢谢.

Rob*_*sor 6

这将为您提供有关导致错误的方法(堆栈跟踪)的大量信息

MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Run Code Online (Sandbox Code Playgroud)