Exceptions.h

Go to the documentation of this file.
00001 #ifndef __LDK_EXCEPTIONS_H__
00002 #define __LDK_EXCEPTIONS_H__
00003 
00005 //   Copyright (C) 2003-2006 Lorien Dunn.
00006 //
00007 //   Contact: loriendunn AT users DOT sourceforge DOT net
00008 //
00009 //   This software is provided 'as-is', without any express or implied warranty.
00010 //   In no event will the authors be held liable for any damages arising from
00011 //   the use of this software.
00012 //
00013 //   Permission is granted to anyone to use this software for any purpose,
00014 //   including commercial applications, and to alter it and redistribute it
00015 //   freely, subject to the following restrictions:
00016 //
00017 //   1. The origin of this software must not be misrepresented; you must not
00018 //   claim that you wrote the original software. If you use this software in a
00019 //   product, an acknowledgment in the product documentation would be
00020 //   appreciated but is not required.
00021 //
00022 //   2. Altered source versions must be plainly marked as such, and must not be
00023 //   misrepresented as being the original software.
00024 //
00025 //   3. This notice may not be removed or altered from any source distribution.
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 }//namespace LDK
00246 
00247 
00248 
00249 #endif //__LDK_EXCEPTIONS_H__

Generated on Fri Aug 17 18:32:26 2007 for LDK by  doxygen 1.5.1