Re: Exception Handling in Release Mode
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/