.NET - 第一次机会异常监听器密集调试? [英] .NET - First chance exception listener for intensive debugging?

查看:188
本文介绍了.NET - 第一次机会异常监听器密集调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是不现实的,但它有可能使一个组件的所有第一机会异常存在的在其过程中得到通知?

This is probably unrealistic, but would it be possible to enable a component to be notified of all first chance exceptions occuring in its process?

我们有一些第三方(由我们签约),这不能做任何事情,但吃excepitions和业务关系的政治使整个磨难皇家疼痛的组件。

We have some third-party (contracted by us) components which fail to do anything but eat excepitions and the politics of the business relationship make the whole ordeal a royal pain.

我们也都知道,我们的一些code正在执行让异常消失的深渊,而不是用我们的集中式例外记录令人失望的作用。

We also are aware that some of our code is performing the disappointing action of letting exceptions vanish into the abyss rather than using our centralized exception logger.

我想我们的应用程序都必须开始作为一个调试应用程序来实现的效果的一个子进程,但我想这是值得一问:)

I assume our application would have to be started as a child process of a debugging application to achieve the effect, but I figure it's worth asking :)

推荐答案

.NET 4.0实际上已经增加了的 AppDomain.FirstChanceException 事件。它发射的任何catch块被执行之前。

Net 4.0 has actually added the AppDomain.FirstChanceException event. It fires before any catch block is executed.

MSDN文章有一些例子。

基本上你只需要添加一个事件处理程序是这样的:

Basically you just add an event handler like this:

    AppDomain.CurrentDomain.FirstChanceException += 
        (object source, FirstChanceExceptionEventArgs e) =>
        {
            Console.WriteLine("FirstChanceException event raised in {0}: {1}",
                AppDomain.CurrentDomain.FriendlyName, e.Exception.Message);
        };

这篇关于.NET - 第一次机会异常监听器密集调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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