Best Error Handling in Games

Started by
19 comments, last by SiCrane 18 years, 6 months ago
Yes, it is a good idea to have a logger class that is avaliable to even the lowest classes in the hierarchy, so that they can report the errors. For that, I have an error handler class that any other class can announce their errors to. Basically, it has the logger and the additional functionality to somehow notify end user of the errors.
Advertisement
When I was in college we used the Borland CPP compiler and I have stuck with that company ever since. However, when running/debuggin etc a program using the Borland CPP Builder 5 IDE, everytime a exception is thrown, the program crashes and reverts back to the IDE, even though the program does handle the exception. With that problem, I tend to stay away from throwing exceptions as much as I can since it is impossible to trace a program in the IDE after that exception has been thrown.
@AP over me:

In Delphi at least you can tell the debugger which exceptions to ignore so the debugger won't stop your program. I guess you can do the same in BCB.
edit-
Quote:Original post by SiCrane
You should throw exceptions by value and catch by reference. Throwing by reference is bad mojo since it creates lifetime issues on the exception object.


Er, you're right. That's what I get for posting right after I wake up, I guess.

Still, the only overhead should be the object's construction since no copies are being made for the catch blocks.

[Edited by - Paradoxish on October 12, 2005 8:54:05 AM]
You should throw exceptions by value and catch by reference. Throwing by reference is bad mojo since it creates lifetime issues on the exception object.
Hi I'm new. What's up?
As far as plain C++ goes, exceptions would be the language's answer to error-handling. And it is a pretty good approach to take.

However the game company which is about to offfer me a job ban exception-handling in their code because they claim that on consoles, exception handling is implemented extremely badly and it's slow. I'm not sure if this is true or they are just doing it like that because once upon a time they were told it...?
From what I understand, that's true for the PS2, but not really true on the XBox. Second hand information here, your milage may vary.
Quote:Original post by Paradoxish
Still, the only overhead should be the object's construction since no copies are being made for the catch blocks.


No, throwing exceptions is a fairly expensive operation, and has more overhead than just construction of the exception, especially if you use asynchronous exception handling.
I may add one thing I read in the "99 cpp goatchas" book

Don t check for successful memory allocation with new
Why?

New should throw a std::bad_alloc exception in the latest version of the stl
and thus will never reach the position when you check of NULL and do your own error handling and in 99% of the cases that new failes you won t be able to succeed anymore

They suggested to catch a bad_alloc exception somewhere at the top of the program so you can stop it and save data to avoid loss of information and work
however this can be ignored in FPS games, on strategy games however you should dea with it, nothing is more annoying than playing hours and hours on a multiplayer match and suddenly it crashes and all the game stats are lost :)

http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement