Jump to content
  • Advertisement
Sign in to follow this  
littlekid

C++ Standard library and exceptions

This topic is 2897 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

Actually, you're both technically wrong :P

Throwing an exception in a function specified as throw() will call std::unexpected (a function, not an exception type). By default, that handler just calls terminate, but it doesn't have to. It may also throw an exception.

Of course, MSVC ignores this and just makes throwing from a throw() function undefined behavior.

Share this post


Link to post
Share on other sites
Advertisement
All this really makes throwing exception a big headache, will it be more elegant and well defined in the C++0x standard, like it becomes clearer and more enforced over which functions/members throws or does not throw?

regards

Share this post


Link to post
Share on other sites
Quote:
Original post by Shinkage
It may also throw an exception.

And if it throws an exception, and it doesn't match the exception specification, which is impossible for a throw() function, terminate() is called.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by Shinkage
It may also throw an exception.

And if it throws an exception, and it doesn't match the exception specification, which is impossible for a throw() function, terminate() is called.


Yes, but it's also possible for it to do none of the above... although I can't imagine when you'd actually want that. I guess the moral of the story is, don't count on throw() enforcing any kind of reliable behavior.

EDIT: Actually, now I can imagine--it may call exit() or abort() instead!

Share this post


Link to post
Share on other sites
unexpected may not return and if it throws an exception when handling a throw() function, terminate() is called. Whatever you want to call it, the program must stop executing.

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.

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!