![]() |
VR-Link API Documentation for HLA 1516
|
00001 /******************************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *******************************************************************************/ 00008 #pragma once 00009 00010 #include "vlMachineTypes.h" 00011 #include <exception> 00012 #include "vlString.h" 00013 #include "vlFilename.h" 00014 #include <iosfwd> 00015 00016 00017 #ifdef DtUSE_UTILITIES_NAMESPACE 00018 namespace DtUSE_UTILITIES_NAMESPACE 00019 { 00020 #endif 00021 00022 00033 class DT_DLL_VLUTIL DtException 00034 { 00035 public: 00036 00039 DtException(const char *errorMessage, 00040 const DtException *previousException = 0) throw() ; 00041 00045 DtException(const char *errorMessage, 00046 const char *functionName, 00047 const char *fileName, 00048 unsigned int lineNumber, 00049 const DtException *previousException = 0) throw(); 00050 00052 DtException(const DtException& other) throw(); 00053 00055 DtException& operator=(const DtException& other) throw(); 00056 00058 virtual~DtException() throw(); 00059 00062 virtual const DtException *lastException() const throw(); 00063 00066 virtual const DtException& initialException() const throw(); 00067 00069 virtual const char* message() const throw(); 00070 00073 virtual DtString what() const throw(); 00074 00076 virtual DtString where() const throw(); 00077 00078 protected: 00079 DtString myLocationMessage; 00080 DtString myErrorMessage; 00081 DtException *myChainedException; 00082 00083 }; 00084 00094 template <int I> 00095 class DtTemplatedException: public DtException 00096 { 00097 public: 00098 00100 DtTemplatedException(const char *errorMessage, 00101 const DtException *previousException = 0) throw(): 00102 DtException(errorMessage, previousException){} 00103 00105 DtTemplatedException(const char *errorMessage, 00106 const char *functionName, 00107 const char *fileName, 00108 unsigned int lineNumber, 00109 const DtException *previousException = 0) throw(): 00110 DtException(errorMessage, functionName, fileName, lineNumber, previousException){} 00111 00113 DtTemplatedException(const DtTemplatedException& other) throw() : DtException(other) 00114 {} 00115 00117 DtTemplatedException& operator=(const DtTemplatedException& other) throw() 00118 {DtException::operator=(other); } 00119 00120 virtual ~DtTemplatedException() throw(){} 00121 00122 private: 00126 int retVal() const { return I;} 00127 }; 00128 00131 const int DtInvalidInputNumber = ~0; 00132 00134 typedef DtTemplatedException<DtInvalidInputNumber> DtInvalidInput; 00135 00138 const int DtUnknownExceptionNumber = ~1; 00139 00141 typedef DtTemplatedException<DtUnknownExceptionNumber> DtUnknownException; 00142 00145 const int DtCorruptedStateNumber = ~2; 00146 00148 typedef DtTemplatedException<DtCorruptedStateNumber> DtCorruptedState; 00149 00152 #ifndef __DtFUNC__ 00153 #if defined(__GNUC__) 00154 #define __DtFUNC__ __PRETTY_FUNCTION__ 00155 #elif defined(_WIN32) && (_MSC_VER != 1200) 00156 #define __DtFUNC__ __FUNCSIG__ 00157 #else 00158 #define __DtFUNC__ "-Unknown Function-" 00159 #endif 00160 #endif /* __DtFUNC__ */ 00161 00164 #define DtTHROW_NEW(exceptionClass,errorMsg) \ 00165 throw exceptionClass(DtString(#exceptionClass": ") + errorMsg, __DtFUNC__, DtFilename::stripPath(__FILE__), __LINE__, 0) 00166 00168 #define DtTHROW_PROPAGATE(exceptionClass, errorMsg, exPtr) \ 00169 throw exceptionClass(DtString(#exceptionClass": ") + errorMsg, __DtFUNC__, DtFilename::stripPath(__FILE__), __LINE__, exPtr) 00170 00173 #define DtCATCH_AND_PROPAGATE(exceptionClass) \ 00174 catch( DtException &ex) \ 00175 {\ 00176 throw exceptionClass("Propagating DtException.", __DtFUNC__, DtFilename::stripPath(__FILE__), __LINE__, &ex);\ 00177 }\ 00178 catch(std::exception &sexception)\ 00179 {\ 00180 DtString error("std::exception ");\ 00181 error += sexception.what();\ 00182 throw exceptionClass(error.c_str(), __DtFUNC__, DtFilename::stripPath(__FILE__), __LINE__, 0); \ 00183 }\ 00184 catch(...)\ 00185 {\ 00186 throw DtUnknownException("Caught Unknown Exception.", __DtFUNC__, DtFilename::stripPath(__FILE__), __LINE__, 0);\ 00187 } 00188 00194 #define DtCATCH_AND_WARN(stream) \ 00195 catch (DtException &ex) \ 00196 { \ 00197 stream << "Caught DtException with stack: \n" << ex << std::endl; \ 00198 } \ 00199 catch (std::exception &sexception) \ 00200 {\ 00201 stream << "Caught std::exception: " << sexception.what() << std::endl; \ 00202 }\ 00203 catch (...) \ 00204 { \ 00205 stream << "Caught Unknown Exception in. " << __DtFUNC__ << "[" << DtFilename::stripPath(__FILE__) << ":" \ 00206 << __LINE__ << "]" << std::endl; \ 00207 } 00208 00218 #define DtPROPAGATE(functionBody)\ 00219 { try\ 00220 functionBody\ 00221 DtCATCH_AND_PROPAGATE(DtCorruptedState)\ 00222 } 00223 00226 DT_DLL_VLUTIL std::ostream & operator << (std::ostream &, const DtException &); 00227 00229 00230 #ifdef DtUSE_UTILITIES_NAMESPACE 00231 } 00232 #endif