473,385 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exception Handling in Release Mode

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

Feb 15 '07 #1
6 3349
Mohan 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.??
Division by zero invokes undefined behavior, so anything might happen. The
C++ standard doesn't require an exception to be thrown. My guess would be
that your compiler adds an extra check in "Debug" mode, and "Win32Release"
mode, it's left out for efficiency reasons.
Feb 15 '07 #2
"Mohan" <ra*******@rediffmail.comwrote in
news:er**********@daniel-new.mch.sbs.de:
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;
Division by zero. Undefined Behaviour. Anything can happen here. Just
happens in your case that something that kinda looks like an exception is
thrown.
}
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.??
From a C++ Standard point of view, no. Since division by zero invokes
Undefined Behaviour, we cannot speculate on what may happen. (However,
look up Structured Exception Handling in your compiler's documentation.
No, it's not a real C++ exception. And is off-topic for this newsgroup.
Further questions on SEH should be directed to a Microsoft newsgroup.)
Feb 15 '07 #3
On Thu, 15 Feb 2007 14:59:29 +0700, Mohan 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;
Divide by zero is not guaranteed to throw a C++ exception - no idea why it
appears to do so in VC++ 6 debug mode.

Also, be aware that the VC++ 6 compiler is very old, buggy and not very
standards-compliant - think about getting hold of a more modern compiler.

[...]

--
Lionel B
Feb 15 '07 #4

Mohan wrote:
It is working fine in Win32 Debug build, but it is not catching the
exception in Win32Release mode.
1.
In the code
try
{
int m = 17/i;
}
"m" is assigned, but never used, and in "Win32Release mode" can be optimized
and the try block can be removed. To always get the error, place the "int
m=0;" declaration into global scope.

2.
You can try to use signals and manual trap points, but it is not beauty
solution and not always work.

#include <signal.h>
int trap_point=0;

extern "C" void your_signal_handler(int)
{
signal(SIGFPE,your_signal_handler);
cout<<"SIGFPE catched"<< endl;

//here system-depended can you continue after signal or not
//CPU and OS mostly can, because they store
//point of execution of synced hardware exception
//but C++ library not always use the data correctly
}

int main(int argc, char* argv[])
{
int i = 0;
signal(SIGFPE,your_signal_handler);
>
try
{
enum {THE_POINT=1};
trap_point=THE_POINT;
int m = 17/i;
//Here SIGFPE can be catched and processed to continue execution
if( !trap_point )throw THE_POINT;
}
catch(...)
{
cout<<"Main - Catch"<<endl;
}
cout <<"End of Main" <<endl;

return 0;
}

--
Maksim A. Polyanin

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Feb 15 '07 #5
On 15 Feb., 08:59, "Mohan" <ramamo...@rediffmail.comwrote:
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.
replace return 0; with return m; to force the compiler to do the
division, then is should work.
Rüdiger
Feb 21 '07 #6
On Wed, 21 Feb 2007 08:20:59 -0800, ruediger.meyer wrote:
On 15 Feb., 08:59, "Mohan" <ramamo...@rediffmail.comwrote:
>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
Feb 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
Hello, I have a Windows Forms application in which I've implemented custom exception handling for most of the UI-related methods. If an exception occurs, it is "caught" and passed on to a...
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
28
by: Frank Puck | last post by:
Meanwhile there are at least 8 years that compilers exist, which provide a working implementation of C++ Exception Handling. Has anything changed meanwhile? From my point of view nothing has...
9
by: David B | last post by:
Why is it so difficult to report bugs to Microsoft? I have a documented bug and an small test example. I don't really see why I should have to pay to tell them about it... Anyway, the...
9
by: Claudio Di Flumeri | last post by:
Hello all, I've added a global exception handler to my application in this way: Sub Main() AddHandler Application.ThreadException, AddressOf ThreadException AddHandler...
5
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can...
6
by: Robin Riley | last post by:
Hi, I have a .NET solution that contains a dll project and a tester application project which, of course, invokes the dll. The dll project has exception handling in it. What's happening is that...
5
by: Tim Zych | last post by:
What factor would allow an unhandled exception to occur in a compiled project, versus no error for the same action during development? In other words, I have a project that, in development when I...
6
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.