Page 1 of 1

How do we deal with exceptions?

Posted: Thu May 26, 2011 1:16 pm
by alt_turo
C++ has a pretty useful exceptions facility. Currently the game does not use it. We need to think about whether we want to and how to handle failures.

Currently for example renderer initialization failure must explicitly be checked. This works pretty well but the error message passing is slightly messy.

Physics initialization failure is in a far worse shape. Since this is a fatal condition and we aren't using exceptions the code has to pull some really nasty things to get out of fullscreen and show comprehensible error message. This mess is actually not fully implemented in Claw but it can be seen in the yet unreleased Shadowgrounds Linux source code. Part of it is in system/Miscellaneous.cpp

So we need some better way to handle exceptional conditions. There are two basic ways: return codes and exceptions.

Pros of exceptions:
1. Simpler code. Return codes would have to be checked everywhere which increases code size, adds complexity and is easy to screw up.


Cons of exceptions:
1. The code is currently not exception safe. Lots of refactoring would be required to get there.
2. Exceptions are not supported on consoles and other embedded platforms. This is not a problem for us.
3. C++ exceptions are pretty basic. We might want to look at boost::exception or something like it.
4. There might be problems on Windows when crossing DLL boundaries. If we adopt my proposal about monolithic binaries this goes away.

Questions? Comments? Flames?

Re: How do we deal with exceptions?

Posted: Thu Jun 23, 2011 4:36 pm
by AndySmile
Hey,

I also prefer exceptions, it's a more elegant way to handle with errors and it also makes it easier for the debugging process,
coz an exception will defiantly thrown so that u got some feedback what's wrong instead a simple "return false" or something ;)
Maybe we could insert a exception wrapper like that "throwError("File doesn't exist!")" and the implementation of this
function/method depends on the platform. if it supports exception we throw an exception otherwise we write it into a log file
or something similar.

could be a plan, couldn't it?

see ya
Andy

Re: How do we deal with exceptions?

Posted: Mon Jun 27, 2011 12:05 pm
by alt_turo
AndySmile wrote:coz an exception will defiantly thrown so that u got some feedback what's wrong instead a simple "return false" or something ;)


Yeah, there are a couple of bugs like that in the code. Something returns NULL or -1 as an error code and the caller does not check it before using.

Maybe we could insert a exception wrapper like that "throwError("File doesn't exist!")" and the implementation of this
function/method depends on the platform.

Currently exceptions are supported on all the platforms we support and we're not planning on supporting platforms which don't.

if it supports exception we throw an exception otherwise we write it into a log file
or something similar.

Bad idea. Throwing an exception means something exceptional happened and we can't continue. If we try to somehow continue on we're going to violate some code invariant and the game will probably crash.


could be a plan, couldn't it?

Not really.

Re: How do we deal with exceptions?

Posted: Tue Jun 28, 2011 3:13 pm
by AndySmile
hey,

alt_turo wrote:
AndySmile wrote:if it supports exception we throw an exception otherwise we write it into a log file
or something similar.

Bad idea. Throwing an exception means something exceptional happened and we can't continue. If we try to somehow continue on we're going to violate some code invariant and the game will probably crash.


U're completely right. But that wasn't my thought. I actually had in mind, if no exceptions are support to write that error in a log file, to know about it that an error was occurred. But this isn't important anymore, coz u said that this game will be not developed for platforms without exceptions. In case of using exception, we could catch those exception and write them into a log file, if it's possible. Because, if someone plays the game, he'll not know what that error means and we don't know what was happening. On this way, the players has an error log and can put it into a bug tracker or something, so we know what was happing and can fix it.

see ya
Andy