-
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.
-
March 1st, 2013, 05:43 AM
#13
Re: try/catch don't work under release version???
If you do not know what code will be calling yours, then it is good idea to check whether a passed-in pointer is NULL or not. If it is not NULL, then assume it is valid.
-
March 1st, 2013, 08:46 AM
#14
Re: try/catch don't work under release version???
When a function accepts as a parameter a memory pointer, there are 1 of 4 possibilites:
1) the pointer is correct and points to what is expected
2) the pointer is NULL. This may or may not be an error depending upon the interface specification
3) the pointer references valid memory in the program address space but does not point to what is expected
4) the pointer references invalid memory outside of the program address space
If you want to undertake pointer parameter checking, then 2) can be done easily, if required, by testing the pointer for NULL and if it is then throwing an exception. 4) will cause an exception when the memory is accessed - so use some statements that access the memory which won't be optimised away by the complier if the result isn't used. 3) can really only be checked by using the factory method as Paul outlined in post #29. This would require changes to all programs that use the function as they would have to obtain the factory produced handle and pass as function argument the factory handle rather than just a pointer to some memory. The only way that 3) can be checked for easily - and is not guarenteed - is to have some 'magic number' stored in a class member variable by the class constructor which can be tested whenever a pointer to the class is referenced.
What level of checking a particular function does on its provided arguments is really down to overall system design/architecture and the tradeoff between robustness and speed. In some environments the level of checking performed is determined by compile time pre-processor identifiers. So there is the 'debug' version with all checking on and the 'release' version with only the most basic (or no) checks. But whatever checking is done or not done on function parameters should be stated clearly in the function contract documentation so that users of the function are aware.
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
|