During the running process of the software, abnormal crashes such as memory out-of-bounds, memory access, stack overflow, thread stack overflow, null pointer and wild pointer will often occur. Just relying on Debug and Release debugging is not enough, because some crashes are not necessary. Now, or it is difficult to appear under Debug. Therefore, we need to add an exception capture module to the software, and generate a dump file containing the exception context when an exception is captured for later analysis using windbg. In this article, we will briefly introduce how to set the exception callback function and how to generate a dump file that saves the exception information.
1. Introduction to API function SetUnhandledExceptionFilter
The Windows system provides the API function SetUnhandledExceptionFilter to set the exception handling function , which is declared as follows:
LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter(
[in] LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
);
The parameter of this function is the set exception handling function, and the API returns the address of the default exception handling function of the system. When an exception occurs in the software, it will return