Archived

This topic is now archived and is closed to further replies.

Void

SEH problem in release mode

Recommended Posts

Void    126
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.
    
#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;
	}
}
    

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
It''s probably because the divide (IDIV instruction, if you''re compiling x86) wasn''t generated in release mode. Check the disassem.

Share this post


Link to post
Share on other sites
neocron    122

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.

Share this post


Link to post
Share on other sites
Void    126
The funny thing is.. when I enable asynchronous exception handling (/EHa) option, an exception is raised in the divide line, even when the cout is not there (in release mode too)

Share this post


Link to post
Share on other sites