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
00030
00031 #ifndef __EXCEPTIONS_HPP
00032 #define __EXCEPTIONS_HPP
00033 #include <stdexcept>
00034
00035 #include "Defs.hpp"
00036
00037
00038 namespace libecs
00039 {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #define THROW_EXCEPTION( CLASS, MESSAGE )\
00051 throw CLASS( __PRETTY_FUNCTION__, MESSAGE )
00052
00053 #if defined( DEBUG )
00054 #define DEBUG_EXCEPTION( EXPRESSION, CLASS, MESSAGE )\
00055 if( ! ( EXPRESSION ) )\
00056 {\
00057 THROW_EXCEPTION( CLASS, "[ " + String( STR( EXPRESSION ) ) + " ]\n\t"\
00058 + MESSAGE );\
00059 }
00060 #else
00061 #define DEBUG_EXCEPTION( EXPRESSION, CLASS, MESSAGE ) ;
00062 #endif
00063
00064
00065
00066
00067 class Exception
00068 :
00069 public std::exception
00070 {
00071
00072 public:
00073
00074 Exception( StringCref method, StringCref message = "" )
00075 :
00076 theMethod( method ),
00077 theMessage( message )
00078 {
00079 ;
00080 }
00081
00082 ECELL_API virtual ~Exception() throw();
00083
00084 ECELL_API virtual const String message() const;
00085
00086 virtual const char* what() const throw() { return message().c_str(); }
00087 virtual const char* const getClassName() const { return "Exception"; }
00088
00089 protected:
00090
00091 const String theMethod;
00092 const String theMessage;
00093 };
00094
00095
00096
00097
00098
00099
00100 #define DEFINE_EXCEPTION( CLASSNAME, BASECLASS )\
00101 class CLASSNAME : public BASECLASS\
00102 {\
00103 public:\
00104 CLASSNAME( StringCref method, StringCref message = "" )\
00105 : BASECLASS( method, message ) {}\
00106 virtual ~CLASSNAME() throw() {}\
00107 virtual StringLiteral getClassName() const\
00108 { return #CLASSNAME ; }\
00109 };\
00110
00111
00112
00113 DEFINE_EXCEPTION( UnexpectedError, Exception );
00114 DEFINE_EXCEPTION( NotFound, Exception );
00115 DEFINE_EXCEPTION( CantOpen, Exception );
00116 DEFINE_EXCEPTION( NotImplemented, Exception );
00117
00118
00119 DEFINE_EXCEPTION( AssertionFailed, Exception );
00120 DEFINE_EXCEPTION( AlreadyExist, Exception );
00121 DEFINE_EXCEPTION( ValueError, Exception );
00122 DEFINE_EXCEPTION( TypeError, Exception );
00123
00124
00125 DEFINE_EXCEPTION( SimulationError, Exception );
00126 DEFINE_EXCEPTION( InitializationFailed, SimulationError );
00127 DEFINE_EXCEPTION( RangeError, SimulationError );
00128
00129
00130 DEFINE_EXCEPTION( PropertyException, Exception );
00131 DEFINE_EXCEPTION( NoSlot, PropertyException );
00132 DEFINE_EXCEPTION( AttributeError, PropertyException );
00133
00134
00135 DEFINE_EXCEPTION( BadID, Exception );
00136 DEFINE_EXCEPTION( BadSystemPath, BadID );
00137 DEFINE_EXCEPTION( InvalidEntityType, BadID);
00138
00139
00140
00141
00142
00143
00144
00145
00146 #define NEVER_GET_HERE\
00147 THROW_EXCEPTION( UnexpectedError, \
00148 "never get here (" + String( __PRETTY_FUNCTION__ )\
00149 + ")." )
00150
00151
00152
00153
00154 }
00155
00156 #endif
00157
00158
00159
00160
00161
00162
00163
00164
00165