Re: Exception Handling in Release Mode
On Wed, 21 Feb 2007 08:20:59 -0800, ruediger.meyer wrote:
On 15 Feb., 08:59, "Mohan" <ramamo...@rediffmail.com> wrote:
Hi,
I am learning the Exception Handling in C++. I wrote a small program using
Exception Handling. I am using Vistual Studio 6.
It is working fine in Win32 Debug build, but it is not catching the
exception in Win32Release mode.
int main(int argc, char* argv[])
{
int i = 0;
try
{
int m = 17/i;
}
catch(...)
{
cout<<"Main - Catch"<<endl;
}
cout <<"End of Main" <<endl;
return 0;
}
Could you please explain, why the Exception is not caught in the
Win32Release mode.??
Thanks
Mohan
m is never used, so the compiler removes the computation of the
division. No division, no exception.
Again: C++ does not require that an exception be thrown for a divide by
zero. So there is no guarantee that this will throw an exception on any
particular C++ implementation.
In fact if I compile and run the above on my system (happens to be gcc on
linux) it prints out:
Floating point exception
and the program terminates (whether m is "used" or not). In other words,
*no C++ exception is thrown* by the divide by zero (rather it appears that
the runtime system traps the divide by zero and causes the program to
terminate, perhaps by sending it some signal... but that's by-the-by).
replace return 0; with return m;
Ummm... did you actually try that (won't compile, of course, as m is out
of scope at the return statement).
to force the compiler to do the division, then is should work.
.... for some strange value of "work"
--
Lionel B