Sign in to follow this  
Raeldor

Error Handling in Cross Platform Game Engine

Recommended Posts

Hi All, How would you do this? Would you simply use boolean returns from functions to indicate success or failiure, or would you implement your own error numbers? Would you use an XML file or something to link error numbers to error descriptions? Can XML handle unicode or international lanuages? Thanks

Share this post


Link to post
Share on other sites
Exceptions with descriptions attached, and logging to file and console wherever the exception is caught.

And yes, XML can handle that stuff. Just use UTF-8 encoding and mark it appropriately in the header.

Share this post


Link to post
Share on other sites
Why not just use a try/catch block and implement classes to handle specific error conditions? As far as I'm aware (correct me if I'm wrong) try/catch is part of the C++ standard (assuming you're using C++ but VB/C# also have their own try/catch blocks) and is not tied directly to any platform:


try
{
// problem encountered
throw CSomeExceptionClass();
}
catch( CSomeExceptionClass var )
{
// do something here with the exception class
}
catch( ... )
{
// apparently something happened you weren't expecting but
// catch it anyways and handle it as gracefully as you can
}


As for your question about XML yes it will handle international languages as long as you properly set the encoding in the xml declaration. Just be careful though as the same rules apply when using international languages as when using standard UTF-8 regarding invalid characters.

Share this post


Link to post
Share on other sites
Thanks for the replys. For stuff that's not a catastrophic failiure, are error numbers still a good way to go to trap the conditions? Should I try and keep consistency and have an error number returned from a failed function even if there is only one point of failure, or should I just return a bool from that function?

I am thinking more of support functions here, such as reading incorrect values from a file, etc.

Share this post


Link to post
Share on other sites
I'd go for consistency. Less thinking that way, you avoid the pain of having to change your bool to an int if the function gets more complex, etc.

Geoff

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this