有没有一种方法来记录或拦截第一次机会异常方法来、异常、机会

2023-09-05 23:14:19 作者:万物不及蔡徐坤

短,有什么办法里面一个正在运行的程序来检测第一次机会异常?理想情况下,我想记录不可用,一旦catch块接管了最后的异常的更详细的状态信息。

Short of using a profiler, is there any way inside a running program to detect first chance exceptions? Ideally, I would like to record more detailed state information that is not available once the catch block has taken over the final exception.

推荐答案

我在Google上搜寻FirstChanceException,我无法抗拒回答这个两年多后...

I was googling FirstChanceException, and I can't resist answering this more than two years later...

现在,在.NET 4.0中,你可以赶上在AppDomain的FirstChanceException事件。这仅仅是一个事件,所以你不能处理错误,但它似乎是一个很好的,中央的方式来获得对异常是否对其进行处理或没有信息。前一个catch块被允许处理它的FirstChanceException事件被抛出。我还没有发现大量的信息就可以了,但除了微软的文档中,更好的来源之一是Mitch卖家博客。

Now, in .net 4.0, you can catch the FirstChanceException event of the AppDomain. It is an event only, so you can't handle the error, but it seems to be a good, central way to get information on exceptions whether they are handled or not. The FirstChanceException event is thrown before a catch block is allowed to handle it. I haven't found a lot of information on it, but aside from the microsoft documentation, one of the better sources is Mitch Sellers Blog.