00001
00002
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 #ifndef EXCEPTION_H
00030 #define EXCEPTION_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #include <iostream>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00065 class Exception
00066 {
00067 private:
00068
00072 char * file;
00073
00077 unsigned int line;
00078
00082 char * description;
00083
00087 int code;
00088
00097 void
00098 init ( const char * file,
00099 unsigned int line,
00100 const char * description,
00101 int code ) throw ();
00102
00106 void
00107 strip () throw ();
00108
00109
00110 protected:
00111
00112
00113 public:
00114
00118 inline
00119 Exception ( void ) throw ()
00120 {
00121 init( 0, 0, 0, 0);
00122 }
00123
00127 inline
00128 Exception ( const Exception & e ) throw ()
00129 {
00130 init( e.file, e.line, e.description, e.code);
00131 }
00132
00139 inline
00140 Exception ( const char * description,
00141 int code = 0 ) throw ()
00142 {
00143 init( 0, 0, description, code);
00144 }
00145
00154 inline
00155 Exception ( const char * file,
00156 unsigned int line,
00157 const char * description = 0,
00158 int code = 0 ) throw ()
00159 {
00160 init( file, line, description, code);
00161 }
00162
00174 Exception ( const char * file,
00175 unsigned int line,
00176 const char * description1,
00177 const char * description2,
00178 int code = 0 ) throw ();
00179
00192 Exception ( const char * file,
00193 unsigned int line,
00194 const char * description1,
00195 const char * description2,
00196 const char * description3,
00197 int code = 0 ) throw ();
00198
00202 inline
00203 ~Exception ( void ) throw ()
00204 {
00205 strip();
00206 }
00207
00214 inline Exception &
00215 operator= ( const Exception & e ) throw ()
00216 {
00217 if ( this != &e ) {
00218 strip();
00219 init( e.file, e.line, e.description, e.code);
00220 }
00221
00222 return *this;
00223 }
00224
00230 inline const char *
00231 getDescription( void ) const throw ()
00232 {
00233 return description;
00234 }
00235
00243 inline unsigned int
00244 getLine ( void ) const throw ()
00245 {
00246 return line;
00247 }
00248
00254 inline const char *
00255 getFile ( void ) const throw ()
00256 {
00257 return file;
00258 }
00259
00265 inline int
00266 getCode ( void ) const throw ()
00267 {
00268 return code;
00269 }
00270 };
00271
00272
00273
00274
00275
00276
00277
00285 inline std::ostream &
00286 operator<< ( std::ostream & os,
00287 const Exception & e )
00288 {
00289 os << e.getFile() << ":" << e.getLine() << ": "
00290 << e.getDescription() << " [" << e.getCode() << "]";
00291
00292 return os;
00293 }
00294
00295
00296
00297 #endif
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325