]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Exception.hh
port to NetBSD
[chaz/yoink] / src / Moof / Exception.hh
index 2478ca1492a98946133c3133dda8a3219babb683..a63f761ad8b857e8c63e81ca11e68df799f73828 100644 (file)
 #ifndef _MOOF_EXCEPTION_HH_
 #define _MOOF_EXCEPTION_HH_
 
+#include <cstring>
 #include <exception>
-#include <boost/shared_ptr.hpp>
+
+#include <Moof/Math.hh>
 
 
 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
This page took 0.021465 seconds and 4 git commands to generate.