Archived

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

Is using exceptions OK?

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