Quote:Original post by ApochPiQ
The first two throw an exception quite reliably for me. Maybe you should post your entire test code so we can see if there's something else involved. (It might be that your CPU doesn't support hardware div-0 exceptions, or they're disabled for some reason, but that seems unlikely.)
The third will not throw an exception; detecting that is not so easy. (Think about it - if an exception was thrown every time you access an array out of bounds, why doesn't it reliably crash programs?) EXCEPTION_ARRAY_BOUNDS_EXCEEDED requires that the hardware supports bounds checking and some other housekeeping code has to be in place. In general, it's safe to say you'll never see this exception - and even if you do, never count on it occurring.
I just did a little rebuild (takes ages if you have >50 files in the project; and changing excpetion handling options does require a full rebuild) and tested it in debug mode - the division by zero is caught as expected.
AS for EXCEPTION_ARRAY_BOUNDS_EXCEEDED - I'd be glad enough if it worked in debug mode because there's nothing that would ever come close, in terms of debugging time, to inadvertently writing over array bounds.
Why this is so important to me is 3rd part code that is executed in a different module - I need to be able to intelligently handle divisions by zero (which in my case, if the programmer is sloppy, can mean that the output of the plugin would most likely be garbage and not worth waiting for).
EXCEPTION_RECORD rec; CONTEXT con; __try { int d = rand() % 2; if(d != 1) d = 1; int a = d - 1; int c = d / a; float fa = 1.f; float fc = fa / (fa - fa); char str[1024]; sprintf(str, "%f %f %f", fa, fb, fc); MessageBox(0, str, 0, 0); int overflow[100000000]; } __except( rec = *(GetExceptionInformation())->ExceptionRecord, con = *(GetExceptionInformation())->ContextRecord, EXCEPTION_EXECUTE_HANDLER) { MessageBox(0, 0, "Undefined exception", 0); }
The above code is like a knife and exceptions are like hot butter: integer division by zero, ignored; floating-point division by zero, ignored (produces the expected 1.#INF); stack overflow, ignored.
PS - I'm using purely structured exceptions and I can see absolutely no change in program behaviour no matter whether it's compiled with the /EHsc (C++ exception handling) or the /EHa (structured exception handling) flag.
PPS - I have floating-point exceptions enabled in compiler settings.
PPPS - I have an AthlonXP 1400+. I couldn't rightfully tell if it supports hardware div-by-zero exception notifications, but I'd sort of expect it to... :/