-
January 7th, 2011, 04:44 PM
#1
try/catch don't work under release version???
I use try/catch a lot in my project. They work fine under debug version but it seems the exceptions are not caught under release version. I am using VS2010. Thanks.
-
January 7th, 2011, 04:53 PM
#2
Re: try/catch don't work under release version???
Thanks for the info.
Victor Nijegorodov
-
January 7th, 2011, 04:56 PM
#3
Re: try/catch don't work under release version???
Originally Posted by VictorN
Thanks for the info.
This is not for the info purpose only and I am also looking for the answer. :-)
-
January 7th, 2011, 05:02 PM
#4
Re: try/catch don't work under release version???
Originally Posted by LarryChen
This is not for the info purpose only and I am also looking for the answer. :-)
But you didn't ask a question!
Victor Nijegorodov
-
January 7th, 2011, 05:07 PM
#5
Re: try/catch don't work under release version???
Originally Posted by VictorN
But you didn't ask a question!
Okey, Actually my project works fine under debug version but exceptions are not handled under release version. My question is that how am I able to handle the exceptions under release version? Thanks.
-
January 7th, 2011, 05:12 PM
#6
Re: try/catch don't work under release version???
Make sure exceptions are enabled in your project settings.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
January 7th, 2011, 06:00 PM
#7
Re: try/catch don't work under release version???
Originally Posted by D_Drmmr
Make sure exceptions are enabled in your project settings.
I already checked "Enable C++ exceptions" with option /EHa. What else did I miss? Thanks.
-
January 7th, 2011, 06:30 PM
#8
Re: try/catch don't work under release version???
Originally Posted by LarryChen
I already checked "Enable C++ exceptions" with option /EHa. What else did I miss? Thanks.
How do you know that exceptions are not enabled. Did you throw an exception?
Regards,
Paul McKenzie
-
January 7th, 2011, 06:49 PM
#9
Re: try/catch don't work under release version???
You could try fixing whatever is wrong.
-
January 7th, 2011, 07:41 PM
#10
Re: try/catch don't work under release version???
Originally Posted by Paul McKenzie
How do you know that exceptions are not enabled. Did you throw an exception?
Regards,
Paul McKenzie
Like I said if I try to run the project under debug mode, then exceptions will be caught. The exceptions are not caught under release mode under same circumstance.
-
January 7th, 2011, 07:53 PM
#11
Re: try/catch don't work under release version???
Originally Posted by LarryChen
Like I said if I try to run the project under debug mode, then exceptions will be caught. The exceptions are not caught under release mode under same circumstance.
What exceptions? You didn't post any code. How do we know exceptions are actually being thrown in release mode?
Nothing to catch if there is nothing thrown.
In any case, nobody can help you unless you actually give them something to look at.
-
January 7th, 2011, 10:07 PM
#12
Re: try/catch don't work under release version???
Originally Posted by LarryChen
Like I said if I try to run the project under debug mode, then exceptions will be caught. The exceptions are not caught under release mode under same circumstance.
Again, how do you know there are exceptions to be caught? If nothing is thrown, nothing gets caught. So where is your evidence that an exception was thrown and you didn't catch it?
A debug build (one where the _DEBUG preprocessor is set), produces a program that does all sorts of checks that do not exist in release builds. Add to that, a release build is optimized, meaning the code you see in the debugger doesn't match what is actually being executed. The code you claim throws an exception could have been optimized away. So there is no "same circumstance" as a debug build.
Also, what types of exceptions? Memory exceptions? Then you are hoping that the same buggyness in your debug build will exist in your release build to cause an exception to occur?
Regards,
Paul McKenzie
Last edited by Paul McKenzie; January 7th, 2011 at 10:10 PM.
-
January 8th, 2011, 08:42 PM
#13
Re: try/catch don't work under release version???
Originally Posted by Paul McKenzie
Again, how do you know there are exceptions to be caught? If nothing is thrown, nothing gets caught. So where is your evidence that an exception was thrown and you didn't catch it?
A debug build (one where the _DEBUG preprocessor is set), produces a program that does all sorts of checks that do not exist in release builds. Add to that, a release build is optimized, meaning the code you see in the debugger doesn't match what is actually being executed. The code you claim throws an exception could have been optimized away. So there is no "same circumstance" as a debug build.
Also, what types of exceptions? Memory exceptions? Then you are hoping that the same buggyness in your debug build will exist in your release build to cause an exception to occur?
Regards,
Paul McKenzie
There is an access violation exception so that it causes the program crash. So that is why I am sure an exception is thrown but it is not handled under release version. In the source code I do have a handler for such exception but obviously the handler is never called under release version. If as you claimed, a release build is optimized, then I might expect an exception is thrown under debug version but not under release version, which is exactly opposite to what is happening to my project.
-
January 8th, 2011, 09:26 PM
#14
Re: try/catch don't work under release version???
Originally Posted by LarryChen
There is an access violation exception so that it causes the program crash. So that is why I am sure an exception is thrown but it is not handled under release version. In the source code I do have a handler for such exception but obviously the handler is never called under release version. If as you claimed, a release build is optimized, then I might expect an exception is thrown under debug version but not under release version, which is exactly opposite to what is happening to my project.
LarryChen, how do you know you have a access violation being thrown?
The point is, you don't. You haven't said anything to make me think you do anyway.
Debug and release builds will be vastly different, and not every out of bounds memory access will produce an exception.
Try this in both release and debug mode. I have a feeling you will get the exception in release mode that you were expecting.
Code:
*(int*)0 = 0; //This will produce a memory access violation
Edit: Just for clarification. Your code should look like this:
Code:
__try
{
*(int*)0 = 0;
}
__except(GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
{
cout << "Access Violation!" << endl;
}
Works for me, and it should work for you too. Also, keep in mind that this is completely MSVC/Windows specific. This will not work on any other OS or compiler (maybe some other Windows compiler.)
Last edited by Chris_F; January 8th, 2011 at 11:11 PM.
-
February 28th, 2013, 02:19 PM
#15
Re: try/catch don't work under release version???
Sorry to revive a dead thread, but I had this same problem. Try Catch works under debug but not release for x64 compiler using VS2010. The issues seems to be that Try Catch aren't implemented if the compiler is set to optimize the code. Right click project->configuration properties->c/c++->Optimization->disabled under the Release Version should re-enable Try Catch stuff.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|