@Joachim points out correctly about the comma operator problem.
I think, the __except()
should look like this:
__except((GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) ?
EXCEPTION_EXECUTE_HANDLER :
EXCEPTION_CONTINUE_SEARCH)
This will make the exception handler execute if the exception is an access violation. If it's not, the exception will propagate up to the closest outer __try
, if any.
I'm fearing that pTest
is a pointer to a class and it may not need to be dereferenced in order to execute GetValue()
and the compiler recognizes that when optimizations are enabled in the release mode. Or maybe even it sees GetValue()
as useless and does not generate any code to call it. It's also possible that the compiler sees that dereferencing a NULL pointer results in undefined behavior and decides to punish your for it at compile time by screwing with your code, it has every right to do it. gcc is notorious for doing it, for example.