00001 #ifndef __LDK_EXCEPTIONS_H__
00002 #define __LDK_EXCEPTIONS_H__
00003
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00033
00034 #include "LDK/Object.h"
00035 #include <stdexcept>
00036 #include <string.h>
00037
00038
00039 namespace LDK
00040 {
00045
00056 #ifdef _MSC_VER
00057 #pragma warning (disable : 4275)
00058 #endif
00059 class LDK_API Exception : public Object, public std::exception
00060 {
00061 protected:
00062 int mLine;
00063 char mFile[128];
00064 char* mMsg;
00065 public:
00070 Exception(int line, const char* file, const char* msg=NULL);
00071
00072 virtual ~Exception() throw();
00075 inline int line() const throw() { return mLine; }
00076
00079 inline const char* file() const throw() { return mFile; }
00080
00081 virtual const char* what() const throw() { return mMsg; }
00082 };
00083 #ifdef _MSC_VER
00084 #pragma warning (default : 4275)
00085 #endif
00091 class LDK_API RuntimeError : public Exception
00092 {
00093 public:
00094 inline RuntimeError(int line, const char* file, const char* msg=NULL) : Exception(line,file,msg)
00095 {}
00096
00097 inline ~RuntimeError() throw() {}
00098 };
00099 #define LDK_RUNTIME_ERROR(msg) LDK::RuntimeError(__LINE__,__FILE__,msg)
00100
00105 class LDK_API ArgumentError : public RuntimeError
00106 {
00107 public:
00108 inline ArgumentError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00109 {}
00110
00111 inline ~ArgumentError() throw() {}
00112 };
00113 #define LDK_ARGUMENT_ERROR(msg) LDK::ArgumentError(__LINE__,__FILE__,msg)
00114
00119 class LDK_API IOError : public RuntimeError
00120 {
00121 public:
00122 inline IOError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00123 {}
00124
00125 inline ~IOError() throw() {}
00126 };
00127 #define LDK_IO_ERROR(msg) LDK::IOError(__LINE__,__FILE__,msg)
00128
00134 class LDK_API EofError : public IOError
00135 {
00136 public:
00137 inline EofError(int line, const char* file, const char* msg=NULL) : IOError(line,file,msg)
00138 {}
00139
00140 inline ~EofError() throw() {}
00141 };
00142 #define LDK_EOF_ERROR(msg) LDK::EofError(__LINE__,__FILE__,msg)
00143
00148 class LDK_API IndexError : public RuntimeError
00149 {
00150 public:
00151 inline IndexError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00152 {}
00153
00154 inline ~IndexError() throw() {}
00155 };
00156 #define LDK_INDEX_ERROR(msg) LDK::IndexError(__LINE__,__FILE__,msg)
00157
00163 class LDK_API LengthError : public RuntimeError
00164 {
00165 public:
00166 inline LengthError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00167 {}
00168
00169 inline ~LengthError() throw() {}
00170 };
00171 #define LDK_LENGTH_ERROR(msg) LDK::LengthError(__LINE__,__FILE__,msg)
00172
00177 class LDK_API BadAllocError : public RuntimeError
00178 {
00179 public:
00180 inline BadAllocError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00181 {}
00182
00183 inline ~BadAllocError() throw() {}
00184 };
00185 #define LDK_BADALLOC_ERROR LDK::BadAllocError(__LINE__,__FILE__)
00186
00191 class LDK_API NullPtrError : public RuntimeError
00192 {
00193 public:
00194 inline NullPtrError(int line, const char* file, const char* msg=NULL) : RuntimeError(line,file,msg)
00195 {}
00196
00197 inline ~NullPtrError() throw() {}
00198 };
00199 #define LDK_NULLPTR_ERROR LDK::NullPtrError(__LINE__,__FILE__,"Null Pointer")
00200
00205 class LDK_API LogicError : public Exception
00206 {
00207 public:
00208 inline LogicError(int line, const char* file, const char* msg=NULL) : Exception(line,file,msg)
00209 {}
00210
00211 inline ~LogicError() throw() {}
00212 };
00213 #define LDK_LOGIC_ERROR(msg) LDK::LogicError(__LINE__,__FILE__,msg)
00214
00219 class LDK_API NotImplimentedError : public LogicError
00220 {
00221 public:
00222 inline NotImplimentedError(int line, const char* file, const char* msg=NULL) : LogicError(line, file,msg)
00223 {}
00224
00225 inline ~NotImplimentedError() throw() {}
00226 };
00227 #define LDK_NOTIMPLIMENTED_ERROR(msg) LDK::NotImplimentedError(__LINE__,__FILE__,msg)
00228
00233 class LDK_API ThreadError : public LogicError
00234 {
00235 public:
00236 inline ThreadError(int line, const char* file, const char* msg=NULL) : LogicError(line,file,msg)
00237 {}
00238
00239 inline ~ThreadError() throw() {}
00240 };
00241 #define LDK_THREAD_ERROR LDK::LogicError(__LINE__,__FILE__,"ThreadError")
00242
00244
00245 }
00246
00247
00248
00249 #endif //__LDK_EXCEPTIONS_H__