Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DanG

Is using exceptions OK?

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

Is it OK to use exceptions for exceptional situations (like file load failures) in games? I read all this stuff that says STAY AWAY FROM EXCEPTIONS, but never really says why. Opinions?

Share this post


Link to post
Share on other sites
Advertisement
Of course it is OK (some negligible performance penalty though). eg:

do
{
try
{
for_each not loaded files, load it!
}
catch(file error)
{
message box "pls insert game cd"
if cancel pressed
throw user abort
}
}while(not all loaded);

Share this post


Link to post
Share on other sites
Consider this example:

int temp* = new int[5000];
if(someInputParameter < 0) throw logic_error("invalid parameter");
/* some other stuff */
delete[] temp;

...if that exception gets thrown, memory will be leaked. But so long as you know how to avoid this situation, there''s nothing wrong with using exceptions.

Share this post


Link to post
Share on other sites

  • 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!