@@ -10807,7 +10807,7 @@ namespace Catch {
1080710807 { static_cast<DWORD>(EXCEPTION_INT_DIVIDE_BY_ZERO), "Divide by zero error" },
1080810808 };
1080910809
10810- static LONG CALLBACK handleVectoredException (PEXCEPTION_POINTERS ExceptionInfo) {
10810+ static LONG CALLBACK topLevelExceptionFilter (PEXCEPTION_POINTERS ExceptionInfo) {
1081110811 for (auto const& def : signalDefs) {
1081210812 if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
1081310813 reportFatal(def.name);
@@ -10821,7 +10821,7 @@ namespace Catch {
1082110821 // Since we do not support multiple instantiations, we put these
1082210822 // into global variables and rely on cleaning them up in outlined
1082310823 // constructors/destructors
10824- static PVOID exceptionHandlerHandle = nullptr;
10824+ static LPTOP_LEVEL_EXCEPTION_FILTER previousTopLevelExceptionFilter = nullptr;
1082510825
1082610826 // For MSVC, we reserve part of the stack memory for handling
1082710827 // memory overflow structured exception.
@@ -10841,18 +10841,15 @@ namespace Catch {
1084110841 FatalConditionHandler::~FatalConditionHandler() = default;
1084210842
1084310843 void FatalConditionHandler::engage_platform() {
10844- // Register as first handler in current chain
10845- exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
10846- if (!exceptionHandlerHandle) {
10847- CATCH_RUNTIME_ERROR("Could not register vectored exception handler");
10848- }
10844+ // Register as a the top level exception filter.
10845+ previousTopLevelExceptionFilter = SetUnhandledExceptionFilter(topLevelExceptionFilter);
1084910846 }
1085010847
1085110848 void FatalConditionHandler::disengage_platform() {
10852- if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle) ) {
10853- CATCH_RUNTIME_ERROR("Could not unregister vectored exception handler ");
10849+ if (SetUnhandledExceptionFilter(reinterpret_cast<LPTOP_LEVEL_EXCEPTION_FILTER>(previousTopLevelExceptionFilter)) != topLevelExceptionFilter ) {
10850+ CATCH_RUNTIME_ERROR("Could not restore previous top level exception filter ");
1085410851 }
10855- exceptionHandlerHandle = nullptr;
10852+ previousTopLevelExceptionFilter = nullptr;
1085610853 }
1085710854
1085810855} // end namespace Catch
0 commit comments