#qt 使应用程序能够取代进程每个线程的顶级异常处理程序。 调用此函数后,如果在未调试的进程中发生异常,并且异常会将其引入未经处理的异常筛选器,该筛选器将调用 _由 lpTopLevelExceptionFilter_ 参数指定的异常筛选器函数。 [](https://learn.microsoft.com/zh-cn/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter#syntax) ## 语法 ``` cpp LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( [in] LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter ); ``` ## 参数 `[in] lpTopLevelExceptionFilter` 指向顶级异常筛选器函数的指针,每当 [UnhandledExceptionFilter](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-unhandledexceptionfilter) 函数获得控制权且进程未调试时,将调用该函数。 此参数的 **NULL** 值指定 **UnhandledExceptionFilter** 中的默认处理。 filter 函数的语法类似于 [UnhandledExceptionFilter](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-unhandledexceptionfilter):它采用 **LPEXCEPTION_POINTERS** 类型的单个参数,具有 WINAPI 调用约定,并返回 **LONG** 类型的值。 筛选器函数应返回以下值之一。 值 含义 **EXCEPTION_EXECUTE_HANDLER** 0x1 从 [UnhandledExceptionFilter 返回](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-unhandledexceptionfilter) 并执行关联的异常处理程序。 这通常会导致进程终止。 **EXCEPTION_CONTINUE_EXECUTION** 0xffffffff 从 [UnhandledExceptionFilter 返回](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-unhandledexceptionfilter) ,并从异常点继续执行。 请注意,筛选器函数可以通过修改通过其 **LPEXCEPTION_POINTERS** 参数提供的异常信息来自由修改延续状态。 **EXCEPTION_CONTINUE_SEARCH** 0x0 继续正常执行 [UnhandledExceptionFilter](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-unhandledexceptionfilter)。 这意味着遵守 [SetErrorMode](https://learn.microsoft.com/zh-cn/windows/desktop/api/errhandlingapi/nf-errhandlingapi-seterrormode) 标志,或调用“应用程序错误”弹出消息框。 [](https://learn.microsoft.com/zh-cn/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter#return-value) ## 返回值 **SetUnhandledExceptionFilter** 函数返回使用 函数建立的上一个异常筛选器的地址。 **NULL** 返回值表示当前没有顶级异常处理程序。 [](https://learn.microsoft.com/zh-cn/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter#remarks) ## 注解 发出 **SetUnhandledExceptionFilter** 将替换调用进程中所有现有线程和所有未来线程的现有顶级异常筛选器。 _lpTopLevelExceptionFilter_ 指定的异常处理程序在导致错误的线程上下文中执行。 这可能会影响异常处理程序从某些异常(如无效堆栈)中恢复的能力。