C++ error catching
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.
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
/. Muzzafarath
Mad House Software
Edited by - Muzzafarath on June 22, 2000 3:35:48 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
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.
Just makes cleaner looking code.
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:
Regards
Michael
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement