Jump to content
  • Advertisement

Archived

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

Fender148

C++ error catching

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

I''m learning C++ from a book and I''ve reached the point where error catching, using the try and catch statements, is taught. I was wondering if this has any relevance or use in game programming or programming in general. Just curious, thanks.

Share this post


Link to post
Share on other sites
Advertisement
If you're writing a game that you want to release (it doesn't matter if you're releasing it for free) then error catching is extremely important to do. If you for example allocate 1 mb of memory, but you're out of memory. If you don't check whether or not you actually got that memory you wanted, your program will crash, and the user will never know what happened. Wouldn't you rather display a nice message saying "You're out of memory." than just have your program crash?

/. Muzzafarath
Mad House Software

Edited by - Muzzafarath on June 22, 2000 3:35:48 PM

Share this post


Link to post
Share on other sites
Using exceptions is cool because you dont have to do lots of error checking after each function, You can just test if there is an error, and then sort it out later.
Just makes cleaner looking code.

Share this post


Link to post
Share on other sites
Exception handling helps you write cleaner code because you don''t have to call an if(...) statement to test the result of all you function calls.

You can call your functions in the try{} statement and not have to worry about if it failed or not:


try {
Function_Call_1();
Function_Call_2();

// Function_Call_1 or Function_Call_2 may have failed, but
// we can carry on as if everything is fine ...
var_1 = var_2;
}
catch( ... ) {
printf("Some sort of error ...");

// ... because we will deal with the error here once it has been thrown by Function_Call_1 or Function_Call_2
}


Regards
Michael

Share this post


Link to post
Share on other sites
Actually you shouldn''t use exception handling in place of simple logic to take care of errors. If a function/class/etc provides for a way to test for success/failure then you should program for those situations.

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!