Changeset 2171 for code/trunk/src/util/Exception.h
- Timestamp:
- Nov 10, 2008, 12:05:03 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/objecthierarchy merged: 2111-2115,2123,2132-2134,2143-2144,2153-2158,2160-2169
- Property svn:mergeinfo changed
-
code/trunk/src/util
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/src/util merged: 2111,2114,2123,2155,2158,2161-2162
- Property svn:mergeinfo changed
-
code/trunk/src/util/Exception.h
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/src/util/Exception.h merged: 2111,2161-2162
r2103 r2171 43 43 #include "Debug.h" 44 44 45 // Define some ugly macros to make things more clear46 #define CREATE_ORXONOX_EXCEPTION(name) typedef SpecificException<Exception::name> name##Exception;47 #define RETURN_EXCEPTION_CODE(name) \48 case Exception::name: \49 return #name;50 51 52 45 namespace orxonox 53 46 { … … 55 48 { 56 49 public: 57 enum ExceptionType58 {59 General,60 FileNotFound,61 Argument,62 PluginsNotFound,63 InitialisationFailed,64 NotImplemented,65 GameState66 };67 50 68 51 Exception(const std::string& description, int lineNumber, … … 74 57 75 58 virtual const std::string& getFullDescription() const; 76 virtual ExceptionType getType() const = 0;77 59 virtual std::string getTypeName() const = 0; 78 60 virtual const std::string& getDescription() const { return this->description_; } … … 93 75 94 76 95 template <Exception::ExceptionType Type> 96 class SpecificException : public Exception 97 { 98 public: 99 SpecificException(const std::string& description, int lineNumber, 100 const char* filename, const char* functionName) 101 : Exception(description, lineNumber, filename, functionName) 102 { 103 // let the catcher decide whether to display the message below level 4 104 COUT(4) << this->getFullDescription() << std::endl; 105 } 106 107 SpecificException(const std::string& description) 108 : Exception(description) 109 { 110 // let the catcher decide whether to display the message below level 4 111 COUT(4) << this->getFullDescription() << std::endl; 112 } 113 114 ~SpecificException() throw() { } 115 116 ExceptionType getType() const { return Type; } 117 std::string getTypeName() const 118 { 119 // note: break is not necessary due to the return in the macros. 120 switch (Type) 121 { 122 RETURN_EXCEPTION_CODE(General) 123 RETURN_EXCEPTION_CODE(FileNotFound); 124 RETURN_EXCEPTION_CODE(Argument); 125 RETURN_EXCEPTION_CODE(PluginsNotFound); 126 RETURN_EXCEPTION_CODE(InitialisationFailed); 127 RETURN_EXCEPTION_CODE(NotImplemented); 128 RETURN_EXCEPTION_CODE(GameState); 129 default: 130 return ""; 131 } 132 } 77 #define CREATE_ORXONOX_EXCEPTION(ExceptionName) \ 78 class ExceptionName##Exception : public Exception \ 79 { \ 80 public: \ 81 ExceptionName##Exception(const std::string& description, int lineNumber, \ 82 const char* filename, const char* functionName) \ 83 : Exception(description, lineNumber, filename, functionName) \ 84 { \ 85 /* Let the catcher decide whether to display the message below level 4 \ 86 Note: Don't place this code in Exception c'tor because getTypeName() \ 87 is still pure virtual at that time. */ \ 88 COUT(4) << this->getFullDescription() << std::endl; \ 89 } \ 90 \ 91 ExceptionName##Exception(const std::string& description) \ 92 : Exception(description) \ 93 { COUT(4) << this->getFullDescription() << std::endl; } \ 94 \ 95 ~ExceptionName##Exception() throw() { } \ 96 \ 97 std::string getTypeName() const { return #ExceptionName; } \ 133 98 }; 134 99 135 // define the template spcialisations 100 // Creates all possible exception types. 101 // If you want to add a new type, simply copy and adjust a new line here. 136 102 CREATE_ORXONOX_EXCEPTION(General); 137 103 CREATE_ORXONOX_EXCEPTION(FileNotFound); … … 141 107 CREATE_ORXONOX_EXCEPTION(NotImplemented); 142 108 CREATE_ORXONOX_EXCEPTION(GameState); 109 CREATE_ORXONOX_EXCEPTION(NoGraphics); 110 CREATE_ORXONOX_EXCEPTION(AbortLoading); 111 } 143 112 144 #define ThrowException( type, description) \145 throw SpecificException<Exception::type>(description, __LINE__, __FILE__, __FUNCTIONNAME__)113 #define ThrowException(Type, Description) \ 114 throw Type##Exception(Description, __LINE__, __FILE__, __FUNCTIONNAME__) 146 115 147 116 // define an assert macro that can display a message 148 117 #ifndef NDEBUG 149 #define OrxAssert( assertion, errorMessage) \150 assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream().setOutputLevel(ORX_ERROR) << errorMessage << std::endl); \151 assert( assertion)118 #define OrxAssert(Assertion, ErrorMessage) \ 119 Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream().setOutputLevel(ORX_ERROR) << ErrorMessage << std::endl); \ 120 assert(Assertion) 152 121 #else 153 122 #define OrxAssert(condition, errorMessage) ((void)0) 154 123 #endif 155 124 156 }157 158 125 #endif /* _Exception_H__ */ - Property svn:mergeinfo changed
Note: See TracChangeset
for help on using the changeset viewer.