我有一个WinForms应用程序。WinForms从Program.cs开始,其中我们定义了main()。我将此代码放在try-catch块中。
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmSplash());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null)
{
MessageBox.Show(ex.InnerException.ToString());
}
}
}
每当出现win32异常时,此机制将失败,抛出未处理的异常消息并导致应用程序崩溃。
我有两个问题与此代码相关:
1)为什么不捕获win32异常。
2)在最高级别捕获异常是一种好的实践吗。