X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FException.hh;h=a63f761ad8b857e8c63e81ca11e68df799f73828;hp=2478ca1492a98946133c3133dda8a3219babb683;hb=c9e20ac06383b20ceb5404c9237e319c2e90d157;hpb=5fa5f117f28922a7e539a432367960c1a61f837d diff --git a/src/Moof/Exception.hh b/src/Moof/Exception.hh index 2478ca1..a63f761 100644 --- a/src/Moof/Exception.hh +++ b/src/Moof/Exception.hh @@ -29,25 +29,25 @@ #ifndef _MOOF_EXCEPTION_HH_ #define _MOOF_EXCEPTION_HH_ +#include #include -#include + +#include namespace Mf { -struct Exception : public std::exception +class Exception : public std::exception { - enum +public: + + explicit Exception(unsigned code, const char* what = "") { - FILE_NOT_FOUND = 1, - OPENGL_ERROR = 2, - OPENAL_ERROR = 3, - SDL_ERROR = 4 - }; - - explicit Exception(unsigned error) : - code(error) {} + mWhat[sizeof(mWhat)-1] = '\0'; + strncpy(mWhat, what, sizeof(mWhat)-1); + mCode = code; + } virtual ~Exception() throw() {} virtual void raise() @@ -55,24 +55,36 @@ struct Exception : public std::exception throw *this; } - virtual const char* what() const throw() + unsigned code() const throw() + { + return mCode; + } + + const char* what() const throw() { - switch (code) - { - case FILE_NOT_FOUND: - return "file not found"; - case OPENGL_ERROR: - return "opengl error"; - case OPENAL_ERROR: - return "openal error"; - case SDL_ERROR: - return "sdl error"; - } - return "unknown error"; + return mWhat; } - unsigned code; +private: + + unsigned mCode; + char mWhat[1024]; +}; + +namespace ErrorCode { +enum Code +{ + NONE = 0, + FASTEVENTS_INIT, // description + FILE_NOT_FOUND, // path of missing file + RESOURCE_NOT_FOUND, // name of missing resource + SCRIPT_ERROR, // description + SDL_INIT, // description + SDL_VIDEOMODE, // - + UNKNOWN_AUDIO_FORMAT, // - + UNKNOWN_IMAGE_FORMAT, // - }; +} // namespace ErrorCode } // namespace Mf