Click to Rate and Give Feedback
MSDN
MSDN Library
Diagnostics
 SetUnhandledExceptionFilter Functio...
SetUnhandledExceptionFilter Function

Enables an application to supersede the top-level exception handler of each thread of a process.

After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter.

Syntax

LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
  __in  LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
);

Parameters

lpTopLevelExceptionFilter [in]

A pointer to a top-level exception filter function that will be called whenever the UnhandledExceptionFilter function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter.

The filter function has syntax similar to that of UnhandledExceptionFilter: It takes a single parameter of type LPEXCEPTION_POINTERS, has a WINAPI calling convention, and returns a value of type LONG. The filter function should return one of the following values.

Value Meaning

EXCEPTION_EXECUTE_HANDLER
0x1

Return from UnhandledExceptionFilter and execute the associated exception handler. This usually results in process termination.

EXCEPTION_CONTINUE_EXECUTION
0xffffffff

Return from UnhandledExceptionFilter and continue execution from the point of the exception. Note that the filter function is free to modify the continuation state by modifying the exception information supplied through its LPEXCEPTION_POINTERS parameter.

EXCEPTION_CONTINUE_SEARCH
0x0

Proceed with normal execution of UnhandledExceptionFilter. That means obeying the SetErrorMode flags, or invoking the Application Error pop-up message box.

Return Value

The SetUnhandledExceptionFilter function returns the address of the previous exception filter established with the function. A NULL return value means that there is no current top-level exception handler.

Remarks

Issuing SetUnhandledExceptionFilter replaces the existing top-level exception filter for all existing and all future threads in the calling process.

The exception handler specified by lpTopLevelExceptionFilter is executed in the context of the thread that caused the fault. This can affect the exception handler's ability to recover from certain exceptions, such as an invalid stack.

Requirements

Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header

Declared in Winbase.h; include Windows.h.

Library

Use Kernel32.lib.

DLL

Requires Kernel32.dll.

See Also

Structured Exception Handling Functions
Structured Exception Handling Overview
UnhandledExceptionFilter


Send comments about this topic to Microsoft

Build date: 7/1/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Be careful of using this API in a DLL      Fritz_Sands   |   Edit   |  
Extreme care should be taken when using SetUnhandledExceptionFilter in a DLL. If you use this API to set the UnhandledExceptionFilter to an address in a DLL, it is possible that the filter pointer will eventually point into arbitrary code if the DLL unloads. And if you are using this API to reset the pointer to the previous value after use, you may inadvertantly set the pointer into unmapped or remapped memory if the original address had been in a DLL that was unloaded during your use. Since it is extremely difficult for user code to control DLL loading and unloading order (or to predict what will occur with future development), it is best to not use this API within a DLL.
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker