Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 1 and Version 2 of code/Error_handling


Ignore:
Timestamp:
Sep 4, 2008, 2:49:34 PM (16 years ago)
Author:
rgrieder
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/Error_handling

    v1 v2  
    1313
    1414== Exceptions ==
    15 This kind of error handling method is used when the programmer has to handle situations that could go wrong, but shouldn't. This does not count obvious C++ programming mistakes! (see Assertions below) [[br]]
    16 When an exception gets thrown its message, containing file, line number, function name, exception type and programmer message, is displayed via COUT(4). That means you usually don't see them anywhere because it is better left to the programmer to display the error at the right position. But you can still open the log and search for it unless the log debug level is below 4. [[br]][[br]]
     15This kind of error handling method is used when the programmer has to handle situations that could go wrong, but shouldn't. Mind the difference to Assertions below! [[br]]
     16For information about how to use them, see [wiki:Exception Exceptions]. [[br]]
     17A good example for exceptions would be a script compiler. Whenever it encounters bad tokens, it throws an exception with a message. The function calling the parser can then catch that exception, display it and act accordingly. [[br]]
     18We also use Exceptions when loading a level. If one occurs, we can abort and the user can choose another level. Of course this shouldn't happen, but nobody's perfect. [[br]][[br]]
     19Keep in mind that you yourself have to display the exception message at the right spot (they do get displayed automatically in level 4 however).
    1720
    18 To throw an exception you best use the 'ThrowException(type, message)' macro that automatically adds line number, function and file name. 'Type' is a user defined derived class of orxonox::Exception so that different exceptions can be caught with different 'catch' clauses. [[br]]
    19 Currently available types are: [[br]]
    20 || Name || Description ||
    21 || || ||
    22 || General || Anything. Avoid using it and rather define a new one. ||
    23 || FileNotFound || Obviously a file was not found ||
    24 || Argument || A function argument in a parser was wrong. ||
    25 || PluginsNotFound || No Ogre plugins were found but are required ||
    26 || InitialisationFailed || When starting the game engine, something went terribly wrong. ||
    27 || NotImplemented || The feature requested has not yet been implemented ||
    28 || GameState || Something went wrong with a GameState class ||
    29 [[br]]
    3021
    3122== Assertions ==
    3223Last but not least: Assertions. This is very handy programmer's tool. It helps a lot tracking bugs and sets up a newly created class much quicker. [[br]]
    33 When should you use it? Basically, an assertion is used when the programmers assumes that a certain condition is true and that otherwise the program would fail somewhere. [[br]][[br]]
     24When should you use it? Basically, an assertion is used when the programmers assumes that a certain condition is true and that otherwise the program would fail somewhere. In short: Whenever something should never go wrong and can't in the eyes of the programmer. But it mostly will ;)  [[br]][[br]]
    3425An example: In a function, you receive a pointer and do something like ptr->aMemberFunction() while assuming that ptr != 0 because otherwise, you'll probably get a segmentation fault.
    3526