简体   繁体   English

如何在未处理的异常上崩溃

[英]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.

相关问题 如何在未处理的任务异常上崩溃? - How to crash on unhandled Task exception? 防止Winform在未处理的异常上崩溃 - Prevent Winform to crash on unhandled exception Windows Forms 未处理的异常崩溃 - Windows Forms Unhandled Exception Crash 如果后台线程中有未处理的异常,如何使主进程崩溃 - how to crash the main process if there is unhandled exception inside background thread 未处理的异常会使WCF服务崩溃吗? - unhandled exception will make WCF service crash? 如何在Android Http postasync中处理TaskCancelledException? 我不断收到未处理的异常和应用程序崩溃 - How to handle TaskCancelledException in Android Http postasync ? I keep getting unhandled exception and app crash .NET 通用主机:防止应用程序因未处理的异常而崩溃 - .NET Generic Host : Prevent application crash on unhandled exception 为什么后台线程中未处理的异常不会导致应用程序域崩溃? - Why unhandled exception in a background thread doesnt crash the app domain? C#应用程序中未处理的异常会导致应用程序崩溃吗? - Unhandled exception in C# application does it crash the app? Xamarin使用Prism导致Autofac崩溃而形成DependencyService-未处理的异常 - Xamarin Forms DependencyService with Prism with Autofac crash - Unhandled Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM