【发布时间】:2018-09-04 22:19:27
【问题描述】:
我把这段代码放在我的entry point:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
private void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
}
并将这段代码添加到一些button点击:
int num = 10;
int t = 5;
t = t - 5;
int error = num / t;
我的应用程序崩溃了,但没有进入这个事件。
【问题讨论】:
-
我认为这个答案可能会有所帮助:stackoverflow.com/a/16719157/7026554
-
我需要把这个 [STAThread] static void Main() 放在哪里? (我正在使用 WPF)
-
WPF 中的 Main() 是自动生成的,但您可以提供自己的:stackoverflow.com/a/26890426/7026554
-
那么如何模拟和捕捉应用程序崩溃?
标签: c# wpf exception-handling