.NET - First chance exception listener for intensive debugging?

前端 未结 2 1342
太阳男子
太阳男子 2021-01-02 12:02

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?

We have some thir

2条回答
  •  情话喂你
    2021-01-02 12:32

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

    This MSDN article has some examples.

    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);
            };
    

提交回复
热议问题