00001 #ifndef EXCEPTION_H
00002 #define 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 #include <stdarg.h>
00029 #include <iostream>
00030
00031 #ifdef sgi
00032 # include <stdio.h>
00033 #else
00034 # include <cstdio>
00035 #endif
00036
00037 #include <string>
00038 #include <stdexcept>
00039 #include <deque>
00040
00041 using namespace std;
00042
00049 class Exception : public runtime_error {
00050
00055 friend ostream& operator << ( ostream& os, Exception& a ) {
00056 a.print( os );
00057 return os;
00058 }
00059
00064 friend ostream& operator << ( ostream& os, Exception* a ) {
00065 os << *a;
00066 return os;
00067 }
00068
00069 public:
00070
00071
00072
00073
00074 virtual ~Exception( ) throw( ) { }
00075
00080 Exception( ) : runtime_error( "" ) { }
00081
00082 Exception( const Exception& e ) : runtime_error( e.what( ) ) {
00083
00084 this->operator=( e );
00085 }
00086
00090 Exception( const string& arg ) : runtime_error( arg ) {
00091
00092 set_message( arg );
00093 }
00094
00095 Exception& operator= ( const Exception& rhs );
00096
00100 deque<string>::const_iterator begin( ) {
00101 return exception_queue.begin( );
00102 }
00103
00107 deque<string>::const_iterator end( ) {
00108 return exception_queue.end( );
00109 }
00110
00114 string get_message( void ) const {
00115 return exception_queue[ 0 ];
00116 }
00117
00121 void set_message( const string& msg );
00122
00123 void set_rethrow_message( const string& file, const int linenum );
00124
00125 const char* what() const throw();
00126
00127 protected:
00128
00129 deque<string> exception_queue;
00130
00134 virtual void print( ostream& os=cerr ) const;
00135
00136 };
00137
00138 #define RETHROWME( arg ) {arg.set_rethrow_message( __FILE__, __LINE__ ); throw arg;}
00139
00145 #endif