WPF - DispatcherUnhandledException似乎不起作用 [英] WPF - DispatcherUnhandledException does not seem to work

查看:683
本文介绍了WPF - DispatcherUnhandledException似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2008中启动了一个新的WPF项目,然后添加了一些代码来捕获 DispatcherUnhandledException 。然后我向 Window1
添加了一个抛出异常,但错误并不被处理程序所困扰。为什么?

I started a new WPF project in VS2008 and then added some code to trap DispatcherUnhandledException. Then I added a throw exception to Window1 but the error is not trapped by the handler. Why?

   public App()
    {
        this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);

    }

    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        System.Windows.MessageBox.Show(string.Format("An error occured: {0}", e.Exception.Message), "Error");
        e.Handled = true;
    }

 void Window1_MouseDown(object sender, MouseButtonEventArgs e)
    {
        throw new NotImplementedException();
    }


推荐答案

你有调试器处理异常的方法 - 调试/异常...应该允许你准确地配置你想要的处理方式。

This can happen because of the way you have the debugger handling exceptions -- Debug/Exceptions... should allow you to configure exactly how you want it handled.

这篇关于WPF - DispatcherUnhandledException似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆