00001 #ifndef INCLUDE_EXCEPTION_H
00002 #define INCLUDE_EXCEPTION_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 #include <stdexcept>
00037 #include <string>
00038
00039
00040 namespace Loris {
00041
00042
00043
00044
00050
00051 class Exception : public std::exception
00052 {
00053
00054 public:
00055
00056
00066 Exception( const std::string & str, const std::string & where = "" );
00067
00069 virtual ~Exception( void ) throw()
00070 {
00071 }
00072
00073
00074
00079 const char * what( void ) const throw() { return _sbuf.c_str(); }
00080
00086 Exception & append( const std::string & str );
00087
00092 const std::string & str( void ) const
00093 {
00094 return _sbuf;
00095 }
00096
00097
00098 protected:
00099
00101 std::string _sbuf;
00102
00103 };
00104
00105
00106
00107
00111
00112 class AssertionFailure : public Exception
00113 {
00114 public:
00115
00125 AssertionFailure( const std::string & str, const std::string & where = "" ) :
00126 Exception( std::string("Assertion failed -- ").append( str ), where )
00127 {
00128 }
00129
00130 };
00131
00132
00133
00134
00137
00138 class IndexOutOfBounds : public Exception
00139 {
00140 public:
00141
00151 IndexOutOfBounds( const std::string & str, const std::string & where = "" ) :
00152 Exception( std::string("Index out of bounds -- ").append( str ), where ) {}
00153
00154 };
00155
00156
00157
00158
00159
00162
00163 class InvalidObject : public Exception
00164 {
00165 public:
00166
00176 InvalidObject( const std::string & str, const std::string & where = "" ) :
00177 Exception( std::string("Invalid configuration or object -- ").append( str ), where )
00178 {
00179 }
00180
00181 };
00182
00183
00184
00185
00188
00189 class InvalidIterator : public InvalidObject
00190 {
00191 public:
00192
00202 InvalidIterator( const std::string & str, const std::string & where = "" ) :
00203 InvalidObject( std::string("Invalid Iterator -- ").append( str ), where )
00204 {
00205 }
00206
00207 };
00208
00209
00210
00211
00213
00214 class InvalidArgument : public Exception
00215 {
00216 public:
00217
00227 InvalidArgument( const std::string & str, const std::string & where = "" ) :
00228 Exception( std::string("Invalid Argument -- ").append( str ), where )
00229 {
00230 }
00231
00232 };
00233
00234
00235
00236
00239
00240 class RuntimeError : public Exception
00241 {
00242 public:
00243
00253 RuntimeError( const std::string & str, const std::string & where = "" ) :
00254 Exception( std::string("Runtime Error -- ").append( str ), where )
00255 {
00256 }
00257
00258 };
00259
00260
00261
00262
00264
00265 class FileIOException : public RuntimeError
00266 {
00267 public:
00268
00278 FileIOException( const std::string & str, const std::string & where = "" ) :
00279 RuntimeError( std::string("File i/o error -- ").append( str ), where )
00280 {
00281 }
00282
00283 };
00284
00285
00286
00287
00288
00289
00290
00291 #define __STR(x) __VAL(x)
00292 #define __VAL(x) #x
00293 #define Throw( exType, report ) \
00294 throw exType( report, " ( " __FILE__ " line: " __STR(__LINE__) " )" )
00295
00296 #define Assert(test) \
00297 do { \
00298 if (!(test)) Throw( Loris::AssertionFailure, #test ); \
00299 } while (false)
00300
00301
00302 }
00303
00304 #endif