SEH problem in release mode
-
Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]
-
Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]
-
Just to let u know.. There seems to be a problem with SEH raising exceptions in release mode (using VC++ 6 SP4) In release mode, a divide by zero does not raise any exceptions but it does in debug mode. However, if I uncomment the cout line after the divide (in release mode), an exception would be raised. If the program was compile with the /EHa option (asynchronous exception), then an exception is always raised. I didn't do an disassembly but it's probably due to the compiler not generating the divide code since it's not used. [source] #include < windows.h > #include < iostream > #include < stdexcept > using namespace std; void SEH_Translator( unsigned int u, EXCEPTION_POINTERS* pExp ) { throw exception("SEH exception"); } void main() { try { _set_se_translator(SEH_Translator); int x,y; x = 9999; y = 0; int z = x/y; // cause a divide by zero exception // cout << z << endl; // uncommenting this throws an exception in release mode } catch(...) { cout << "Exception caught" << endl; } } [/source]
The reason that an exception doesn't occur in this code in release is because the optimizer will throw all the code away as it does nothing... As soon as you include the cout z has to around so a value can be displayed hence the exception - In a debug build no code is optimized hence you get the behaviour expected.