00001 #ifndef INCLUDE_EXCEPTIONS_H
00002 #define INCLUDE_EXCEPTIONS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdexcept>
00041 #include <string>
00042
00043
00044 namespace Loris {
00045
00046
00047
00048
00054
00055 class Exception : public std::exception
00056 {
00057
00058 public:
00059
00060
00070 Exception( const std::string & str, const std::string & where = "" );
00071
00073 virtual ~Exception( void ) throw()
00074 {
00075 }
00076
00077
00078
00083 const char * what( void ) const throw() { return _sbuf.c_str(); }
00084
00090 Exception & append( const std::string & str );
00091
00096 const std::string & str( void ) const
00097 {
00098 return _sbuf;
00099 }
00100
00101
00102 protected:
00103
00105 std::string _sbuf;
00106
00107 };
00108
00109
00110
00111
00115
00116 class AssertionFailure : public Exception
00117 {
00118 public:
00119
00129 AssertionFailure( const std::string & str, const std::string & where = "" ) :
00130 Exception( std::string("Assertion failed -- ").append( str ), where )
00131 {
00132 }
00133
00134 };
00135
00136
00137
00138
00141
00142 class IndexOutOfBounds : public Exception
00143 {
00144 public:
00145
00155 IndexOutOfBounds( const std::string & str, const std::string & where = "" ) :
00156 Exception( std::string("Index out of bounds -- ").append( str ), where ) {}
00157
00158 };
00159
00160
00161
00162
00163
00166
00167 class InvalidObject : public Exception
00168 {
00169 public:
00170
00180 InvalidObject( const std::string & str, const std::string & where = "" ) :
00181 Exception( std::string("Invalid configuration or object -- ").append( str ), where )
00182 {
00183 }
00184
00185 };
00186
00187
00188
00189
00192
00193 class InvalidIterator : public InvalidObject
00194 {
00195 public:
00196
00206 InvalidIterator( const std::string & str, const std::string & where = "" ) :
00207 InvalidObject( std::string("Invalid Iterator -- ").append( str ), where )
00208 {
00209 }
00210
00211 };
00212
00213
00214
00215
00217
00218 class InvalidArgument : public Exception
00219 {
00220 public:
00221
00231 InvalidArgument( const std::string & str, const std::string & where = "" ) :
00232 Exception( std::string("Invalid Argument -- ").append( str ), where )
00233 {
00234 }
00235
00236 };
00237
00238
00239
00240
00243
00244 class RuntimeError : public Exception
00245 {
00246 public:
00247
00257 RuntimeError( const std::string & str, const std::string & where = "" ) :
00258 Exception( std::string("Runtime Error -- ").append( str ), where )
00259 {
00260 }
00261
00262 };
00263
00264
00265
00266
00268
00269 class FileIOException : public RuntimeError
00270 {
00271 public:
00272
00282 FileIOException( const std::string & str, const std::string & where = "" ) :
00283 RuntimeError( std::string("File i/o error -- ").append( str ), where )
00284 {
00285 }
00286
00287 };
00288
00289
00290
00291
00292
00293
00294
00295 #define __STR(x) __VAL(x)
00296 #define __VAL(x) #x
00297 #define Throw( exType, report ) \
00298 throw exType( report, " ( " __FILE__ " line: " __STR(__LINE__) " )" )
00299
00300 #define Assert(test) \
00301 do { \
00302 if (!(test)) Throw( Loris::AssertionFailure, #test ); \
00303 } while (false)
00304
00305
00306 }
00307
00308 #endif