Errors

Errors Module gives you the unified way to handle an errors in your game.

Any other FeyGamesFramework Module depends on Errors Module. So you always have to include it and choose an implementation of it.

How it works

In fact, Errors Module contains classes like ErrorsHandler. But for you, as a FeyGamesFramework user, you only have to use one #define and don't bother about the rest:

#define ERROR_HANDLE_NO_MODULE(success, errorMessage)

The first parameter is an operation that returns boolean value (true or false) and the second is std::wstring error message that will be used if error occurred (the operation returned false).

So for example:

bool loadMyModel(){...}
//line above will generate an error with given message if loadMyModel() returns false
ERROR_HANDLE_NO_MODULE(loadMyModel(), "Model could not be loaded.");

Any of FeyGamesFramework Modules uses the similar way to handle such situations.

How errors handler will behave

They are 3 customizable aspects of error handling:

  • notification,
  • interruption,
  • logging.

Notification can be set to:

  • silent (you won't see any notification),
  • inform (basic information that error has occurred, good for release version of the game),
  • inform with details (the full details of error, good for debugging the game).

Interruption (do you want application to quit after delivering an error?) and logging (would you like to make an log file?) have to possible values: yes and no.

By default, FeyGamesFramework uses:

  • notification = inform,
  • interruption = no,
  • logging = no.

You can change that for each Module separately by using:

Errors::ErrorsHandler::setErrorHandling(moduleCode, errorNotify, errorQuit, errorLog);

E.g.:

using namespace Errors;
ErrorsHandler::setErrorHandling(MOD_GRAPHIC, ERROR_HANDLE_DETAILS, ERROR_HANDLE_QUIT_YES, ERROR_HANDLE_LOG_NO);
ErrorsHandler::setErrorHandling(MOD_GUI, ERROR_HANDLE_DETAILS, ERROR_HANDLE_QUIT_YES, ERROR_HANDLE_LOG_NO);

Those statements have to be done before you will create and initialize any of Modules, including Errors Module itself.

After that, you should immediately create an ErrorsHandler:

ErrorsModule::createErrorsHandler();

From now on, errors handling will work for you. And now you can create an initialize the rest of Modules.

TODO

  • Check error handling for user-defined errors (without MODULE_CODE).
  • Errors::ErrorsHandler::setErrorHandling() vs Errors::setErrorHandling().
  • Logging an error.