[英]How to crash on unhandled Exception
I have created some custom exceptions in a WPF project and I am pretty sure that I am not catching them, when they get thrown, but my application does not crash either. 我已经在WPF项目中创建了一些自定义异常,并且我很确定在抛出异常时不会捕获它们,但是我的应用程序也不会崩溃。 The Exception is logged in the Output Window though.
但是,该异常记录在“输出”窗口中。
My custom exceptions derive from System.Exception
and I have checked all my try{}catch{}
statements if they catch my custom Exception or System.Exception
. 我的自定义异常源自
System.Exception
并且如果它们捕获了我的自定义Exception或System.Exception
,则我已经检查了所有try{}catch{}
语句。 None of them do that. 他们都没有这样做。 I am using Visual Studio 2010 and am running it on a 32bit machine, so this seems to be a different problem.
我正在使用Visual Studio 2010并在32位计算机上运行它,因此这似乎是一个不同的问题。
You can add a handler for the AppDomain.UnhandledException
event: 您可以为
AppDomain.UnhandledException
事件添加处理程序:
AppDomain.CurrentDomain.UnhandledException += App_UnhandledException;
public void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception = (Exception)e.ExceptionObject;
Error error = new Error(exception, mainViewModel.StateManager.CurrentUser);
mainViewModel.AddError(error);
}
Error
is a custom class that I use to log errors in the database with. Error
是一个自定义类,用于记录数据库中的错误。 If you put a break point in this method, then execution will jump here whenever there are any uncaught Exception
objects that have been thrown. 如果在此方法中设置了一个断点,那么只要抛出任何未捕获的
Exception
对象,执行就会跳到此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.