/*] Copyright (c) 2009-2010, Charles McGarvey [************************** **] All rights reserved. * * vi:ts=4 sw=4 tw=75 * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * **************************************************************************/ #ifndef _MOOF_ERROR_HH_ #define _MOOF_ERROR_HH_ #include // strncpy #include #include namespace Mf { class Error : public std::exception { public: enum Code { UNINITIALIZED = -1, // - NONE = 0, // - ALC_INIT, // description FASTEVENTS_INIT, // description FILE_NOT_FOUND, // path of missing file OPENAL_INIT, // description RESOURCE_NOT_FOUND, // name of missing resource SCRIPT_ERROR, // description SDL_INIT, // description SDL_VIDEOMODE, // - UNKNOWN_AUDIO_FORMAT, // name of resource UNKNOWN_IMAGE_FORMAT, // name of resource }; explicit Error(unsigned code = NONE, const std::string& what = "") { init(code, what); } virtual ~Error() throw() {} void init(unsigned code = NONE, const std::string& what = "") { strncpy(mWhat, what.c_str(), sizeof(mWhat)-1); mWhat[sizeof(mWhat)-1] = '\0'; mCode = code; } virtual void raise() const { throw *this; } unsigned code() const throw() { return mCode; } const char* what() const throw() { return mWhat; } operator bool () const { // resolves to true if error code is not NONE return mCode != NONE; } void reset() throw() { mCode = NONE; mWhat[0] = '\0'; } private: unsigned mCode; char mWhat[1024]; }; } // namespace Mf #endif // _MOOF_ERROR_HH_