00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _pexception_h_
00021 #define _pexception_h_
00022
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/psourceinfo.h>
00025 #include <string>
00026
00027 namespace P {
00028
00030
00038 class PCORE_EXPORT BaseError {
00039 public:
00041
00046 inline BaseError(const char* _what, const SourceInfo& _si) throw()
00047 : m_what(_what), m_sourceInfo(_si) {}
00048
00050 inline virtual ~BaseError() throw() {}
00051
00053
00057 inline const char* what() const throw()
00058 { return m_what; }
00059
00061
00065 inline virtual BaseError* clone() const
00066 { return new BaseError(*this); }
00067
00069
00074 inline const SourceInfo& sourceInfo() const throw()
00075 { return m_sourceInfo; }
00076
00078 BaseError& operator=(const BaseError& e);
00079
00080 private:
00081 const char* m_what;
00082 SourceInfo m_sourceInfo;
00083 };
00084
00086
00093 class PCORE_EXPORT LogicError: public BaseError {
00094 public:
00095 inline LogicError(const char* _what, const SourceInfo& _si) throw()
00096 : BaseError(_what,_si) {}
00097
00098 inline BaseError* clone() const
00099 { return new LogicError(*this); }
00100 };
00101
00103
00107 class PCORE_EXPORT RuntimeError: public BaseError {
00108 public:
00109 inline RuntimeError(const char* _what, const SourceInfo& _si) throw()
00110 : BaseError(_what,_si) {}
00111
00112 inline BaseError* clone() const
00113 { return new RuntimeError(*this); }
00114 };
00115
00117
00118
00119
00120
00121
00122
00124
00125
00126
00127
00128
00129
00130
00132
00136 class PCORE_EXPORT OutOfRangeError: public LogicError {
00137 public:
00138 inline OutOfRangeError(const SourceInfo& _si) throw()
00139 : LogicError("Out of range",_si) {}
00140
00141 inline BaseError* clone() const
00142 { return new OutOfRangeError(*this); }
00143 };
00144
00146
00150 class PCORE_EXPORT OverflowError: public RuntimeError {
00151 public:
00152 inline OverflowError(const SourceInfo& _si) throw()
00153 : RuntimeError("Overflow",_si) {}
00154
00155 inline BaseError* clone() const
00156 { return new OverflowError(*this); }
00157 };
00158
00160
00166 class PCORE_EXPORT SystemError: public RuntimeError {
00167 public:
00168 typedef long oserr_t;
00169
00170 inline SystemError(oserr_t errnum, const char* _what, const SourceInfo& _si) throw()
00171 : RuntimeError(_what,_si), m_errnum(errnum) {}
00172
00173 inline BaseError* clone() const
00174 { return new SystemError(*this); }
00175
00177
00181 inline oserr_t errnum() const throw()
00182 { return m_errnum; }
00183
00185
00190 std::string text() const throw();
00191
00192 private:
00193 oserr_t m_errnum;
00194 };
00195
00197
00201 class PCORE_EXPORT SyncError: public SystemError {
00202 public:
00203 inline SyncError(oserr_t errnum, const char* _what, const SourceInfo& _si) throw()
00204 : SystemError(errnum, _what, _si) {}
00205
00206 inline BaseError* clone() const
00207 { return new SyncError(*this); }
00208
00209 };
00210
00212
00216 class PCORE_EXPORT IOError: public SystemError {
00217 public:
00218 inline IOError(oserr_t errnum, const char* _what, const SourceInfo& _si) throw()
00219 : SystemError(errnum, _what, _si) {}
00220
00221 inline BaseError* clone() const
00222 { return new IOError(*this); }
00223
00224 };
00225
00226 }
00227
00228 #endif