*******************************************************************************/
-#ifndef _MOOF_EXCEPTION_HH_
-#define _MOOF_EXCEPTION_HH_
+#ifndef _MOOF_ERROR_HH_
+#define _MOOF_ERROR_HH_
-#include <cstring>
+#include <cstring> // strncpy
#include <exception>
#include <string>
-#include <Moof/Math.hh>
-
namespace Mf {
-class Exception : public std::exception
+class Error : public std::exception
{
public:
- explicit Exception(unsigned code, const std::string& what = "")
+ enum Code
+ {
+ NONE = 0,
+ ALC_INIT, // description
+ 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, // name of resource
+ UNKNOWN_IMAGE_FORMAT, // name of resource
+ };
+
+ explicit Error(unsigned code, const std::string& what = "")
+ {
+ init(code, what);
+ }
+ virtual ~Error() throw() {}
+
+ void init(unsigned code, const std::string& what = "")
{
mWhat[sizeof(mWhat)-1] = '\0';
strncpy(mWhat, what.c_str(), sizeof(mWhat)-1);
mCode = code;
}
- virtual ~Exception() throw() {}
virtual void raise()
{
return mWhat;
}
+ bool isError() const throw()
+ {
+ return mCode != NONE;
+ }
+
private:
unsigned mCode;
char mWhat[1024];
};
-namespace ErrorCode {
-enum Code
-{
- NONE = 0,
- ALC_INIT, // description
- 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, // name of resource
- UNKNOWN_IMAGE_FORMAT, // name of resource
-};
-} // namespace ErrorCode
-
} // namespace Mf
-#endif // _MOOF_EXCEPTION_HH_
+#endif // _MOOF_ERROR_HH_
/** vim: set ts=4 sw=4 tw=80: *************************************************/