Jump to content
  • Advertisement
Sign in to follow this  
cozzie

short questions on exception handling

This topic is 684 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!