Jump to content
  • Advertisement
Sign in to follow this  

short questions on exception handling

This topic is 769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I have a few questions on exception handling in C++, can someone shed some light on this?


1. When I use a 'throw', in debug mode a nice pop-up shows up, helping me in the direction to solve my underlying problem.

Now when I make a release build and run it outside VS, and this throw is done, the result is 'The pogram has stopped working!'.

Can I assume that independent of the details of the throw (runtime_error, memory allocation etc.) the program will stop working (release mode)?


If so, I know I could decide to add some messagebox or logging line that tells what happened and why the program stopped.


2. Is there any harm/ advice against using 'throw' without a try/catch blok?

With the assumption that it regards situations that are predictable, like if somePtr == nullptr etc.

Some testing showed me that it works perfectly fine, assuming you know that it could occur in some condition.


3. Will a 'throw' only statement in a constructor, make the program call the destructor of this class?

(besides the individual constructors of the member vars in the class).

If not, I should make sure that all class members are 'RAII proof' / have a good destruction method on their own, for pointers CComPtr (smart pointer) etc.


Note; it's ofcourse situational, because I could also have some function return a bool, in this case false, if the input pointer == nullptr.

It's just that I want to know if both options are considered 'OK/ valid'. In exceptional situations I might need just a throw in a constructor (better not, and have some other member function do the tricky stuff, but this is not always possible. This is a balance / design decision; how much initializating does my object need to be in a 'valid state'.


Any input is appreciated.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!