Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi,

I cant catch any exception in Release mode of my program. But debug mode is working fine w/o any problem. I am using VS 2008 as my IDE.

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        printf("About to try\n");
        int j,i=20;
        j=i/0;
        *(char *)j = 0000;
        printf("Try done\n");
    }
    catch(...)
    {
        printf("Caught Exception\n");
    }
    printf("Waiting to stop\n");
    Sleep(5000);
    return 0;
}
Posted
Updated 22-Feb-10 7:52am
v2

Divison by zero or accessing an invalid pointer do not result in C++ exceptions. You may want to look at Structured Exception Handling[^]
 
Share this answer
 
The problem is that divide by zero doesn't cause a C++ exception to be thrown. If you really want to catch that kind of error you could use Structured Exception Handling[^] instead (or in addition to C++ exception handling).
 
Share this answer
 
Thanks for reply Nemanja Trifunovic , Graham Breach.

I found another compiler option which may be helpful in such cases. ie C++ exception handling with structured exception handling exceptions.

<a href="http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx</a>[<a href="http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx" target="_blank" title="New Window">^</a>]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900