473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3364
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 "Win32Relea se"
mode, it's left out for efficiency reasons.
Feb 15 '07 #2
"Mohan" <ra*******@redi ffmail.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 "Win32Relea se 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_han dler(int)
{
signal(SIGFPE,y our_signal_hand ler);
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,y our_signal_hand ler);
>
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...@redi ffmail.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...@redi ffmail.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
652
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 standard exception handler that will format and display the error information and give the user a chance to copy, print, e-mail, etc. I have a problem...
6
2112
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 exe file it doesn't catch any errors? Does anyone know what my problem might be? Regards
28
2217
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 changed -- people are still using a coding style, which I call pre-C++-Exception-Handling. Is this different in your experience? What is your...
9
4987
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 following code exhibits the bug. If it is built and run from Visual Studio.NET 2003 in debug mode it works correctly as expected. However, if built in...
9
2200
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 AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException Application.Run(Main)
5
3286
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 view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the...
6
1783
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 when I run the executable from within the .NET studio environment, thrown exceptions are caught and handled correctly (both debug and release mode)....
5
2087
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 test it, runs no problem. When I compile and release the dll, the user gets an unhandled exception. It doesn't halt the code, it just shows an error...
6
4372
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 restart my application, sometimes several times a day The customer has XP Home SP2
0
7408
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5340
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1891
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.