Is there a way to log or catch first chance exceptions

With the exception of using the profiler, is there any way inside the running program to detect first chance exceptions? Ideally, I would like to record more detailed status information that is not available after the catch block has caught the last exception.

+7
exception
source share
3 answers

I was looking for FirstChanceException, and I can't help answering this more than two years later ...

Now, in .net 4.0, you can catch the FirstChanceException event in the AppDomain. This is an event only, so you cannot handle this error, but it seems to be a good, central way to get information about exceptions, regardless of whether they are handled or not. The FirstChanceException event is thrown before the catch block can handle it. I did not find much information about this, but besides the Microsoft documentation, one of the best sources is the Mitch Sellers Blog .

+16
source share

I think the only way to get this information in .NET is with a debugger.

Otherwise, you will have to independently develop a solution for maintaining the state of the stack frame and a special way of exception logs. Basically you do the same thing that the memory profiler does, keep track of the instances created. This would be a huge success, even if you did not limit the amount of information that you register.

The best solution would be to use the Trace and Assert capabilities in the System.Diagnostics namespace to selectively monitor the status of the program or use the logging tool (log4net, EnterpriseLibrary, NLog, minimize your own simple) to flush the / stack / variable stream when you go .

In any case, adding all this additional information is a big overhead.

EDIT: I received the news of this project in my channel: NTrace . It looks like it will put a little more on what you are trying to do.

+2
source share

Use Adplus . It attaches the debugger to the process and generates (by default) a small mini-drive when the first random excitation rises. The log file created in Adplus also contains exception information. Just make sure you have a PDB capable of seeing complete cassette information.

+1
source share

All Articles