How to define a rule for second chance exceptions

Welcome to Technet. This is my first post about debugging.

Time to time i deliver workshop about ASP.NET Performance and Troubleshooting. I realized that a few people is aware of first chance and second chance exception terms. On the other hand, experts have difficulties how to troubleshoot a second chance exceptions, so i decided to post a blog about how to identify and troubleshoot these type of exceptions.

First of all, we have to know exception types, which can be set as two types as we mentioned previous paragraph:

  • First chance exception

If an unwanted action occurs during the process lifecycle then operating system awares of the action and checks if the process can recover the current status or not. If it decides the process can recover it then operating system throws an exception named first chance exception such as ThreadAbortException and allows the process handle the exception. If it is handled then process continues to its life.

  • Second chance exception

On the other hand, if the process can't handle the exception then it will be terminated by the system and process will be informed via second chance exception by the system. There are 3 types of important second chance exceptions: OutOfMemoryException, StackOverflowException and EngineExecutionException. These 3 exception objects will be created during process start-up with empty stack info and stack info will be filled during second chance exception execution.

If the process gets the second chance exception then it terminates itself and manually getting dump file during this phase is almost impossible, but there are a few methods to create dump file using  debugging tools. In this blog i will introduce how to configure a rule using DebugDiag tool.

Before we decide to create a debugdiag rule, we have to understand that there is a second chance exception scenario on related process. For ASP.NET applications, if we see 5011 EventID in the system event logs then we can certainly say it is second chance exception problem.

At that point we need to create a rule using debug diagnostic tool explained in this blog.

Whenever you define the rule and activate it, debug diag tool will monitor the system and if the ZwTerminateProcess event is fired then tool will create the dump file. On the next step we can analyze the dump file using debug diagnostics analyze tool or windows debugger tool known as WinDbg.

I will try to explain these two analyze methods in the next blog soon.

Till that time, wish you a healthy system 😉

Comments (1)

Skip to main content