#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;
}
}
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.
October 03, 2000 01:32 AM
It''s probably because the divide (IDIV instruction, if you''re compiling x86) wasn''t generated in release mode. Check the disassem.
Yup, since z is local and is only assigned never used, the optimizer (in Release) won''t generate the instructions. When you uncomment your cout code, z is now used and the optimizer will generate the IDIV instruction and you''ll get your exception.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement