Jump to content
  • Advertisement
Sign in to follow this  
wcassella

C++ exceptions

This topic is 1039 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,

 

in various places around the internet I've seen strong recommendations against using exceptions in C++, for a variety of reasons (performance, semantics, code size, etc). Can anyone here make any comment on whether these arguments still hold today? I agree that exceptions aren't necessarily the best means of error handling, but in some cases they meet requirements that return-code style handling simply does not.

 

As game developers I'm sure many of you are biased towards disabling them completely (for the reasons above), but if that's your suggestion I'd appreciate it if you could supply hard evidence from updated compilers to support it.

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement
I do agree with what Sean said.

Exception safety is a complex beast, and these arguments remain.

It used to be that memory and performance were the main concerns of enabling exceptions as was the case with many c++ features we now use blindly without concern. In days of old inheritance was considered a memory and cpu intensive feature.

Do certainly be aware of the issues Sean raised, they are still valid and exceptions can be a minefield waiting to happen.

As I said use them sparingly and for exceptional circumstances. Don't fall into the java trap of having silly exceptions for any minor program condition! -- C++ is not java and is not C#! :)

Share this post


Link to post
Share on other sites

4) the no-throw guarantee. No matter what, your function can never be involved in exceptional stack unwinding.


I would instead put it as "this function will never throw an exception". A little clearer wording.
 

If exceptions are enabled, you should aim for level 3/4 guarantees.


Why? There is nothing wrong with the "basic guarantee" that says "nothing is leaked and I am in a valid, if unspecified, state".

As yourself and others have already stated, trying to provide the "strong" or "no-throw" guarantee is very hard, sometimes impossible, and usually has large penalties.

But there is little to no reason to go for it in a game. Heck, the standard library itself only provides "strong" or "no-throw" when it can do so for little to no cost, and guarantees to provide the "basic" level of exception safety across the board. Edited by SmkViper

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!