I am writing code to test C++ and SEH exceptions. However, on running my code below, the exception again calls the same handler even though I have specified the index to be 0 i.e. the last handler. In my opinion, the ideal handling should be:
SEH exception happens -> Vector Exception Handler is called -> Searches and sees no other handler -> program terminates/Exception is left unhandled.
On running the debugger, I see the output as:
exception caught!
(multiple times when I click on "continue" on VS)
LONG WINAPI HandleVecException(EXCEPTION_POINTERS *exceptionPointers) {
std::cout << "Exception caught!";
return EXCEPTION_CONTINUE_SEARCH;
}
int main() {
// Install the exception filter for the main thread
PVOID handle = AddVectoredExceptionHandler(0,HandleVecException);
try {
int* ptr = nullptr;
*ptr = 42; // Access violation
}
catch(std::exception ex){
//code won't enter here
cout << "Exception" << ex.what();
//std::rethrow_exception(current_exception());
}
RemoveVectoredExceptionHandler(handle);
return 0;
}