diff --git a/src/libCom/misc/locationException.h b/src/libCom/misc/locationException.h new file mode 100644 index 000000000..cc18ef0bc --- /dev/null +++ b/src/libCom/misc/locationException.h @@ -0,0 +1,75 @@ + +// +// $Id$ +// +// Author: Jeff Hill +// + +#ifndef locationException_h +#define locationException_h + +#include +#include +#include + +#include "cantProceed.h" + +template +class locationAndType : public T { +public: + locationAndType (T &); + unsigned lineNumber () const; + const char *fileName () const; + const type_info & typeInfo () const; + void show (unsigned level) const; +private: + unsigned lineNumberCopy; + const char *pFileName; +}; + +template +inline locationAndType::locationAndType (T &tIn, const char *fileName, unsigned lineNumber) : + T (tIn) , lineNumberCopy(lineNumber), pFileName (fileName) {} + +template +inline unsigned locationAndType::lineNumber () const +{ + return this->lineNumberCopy; +} + +template +inline const char * locationAndType::typeInfo () const +{ + return typeid (T); +} + +template +inline const char * locationAndType::lineNumber () const +{ + return this->lineNumberCopy; +} + +template +inline const char * locationAndType::show (unsigned level) const +{ + cerr << "C++ exception=" << typeid(T).name() + << " in file=" << this->pFileName + << " at line=" << this->lineNumberCopy; +} + +#define throwWithLocation (parm) throwExceptionWithLocation (parm, __FILE__, __LINE__); + +template +inline void throwExceptionWithLocation (T &parm, const char *pFileName, unsigned lineNo) +{ + locationAndType lat (parm, pFileName, lineNo); +# ifdef noExceptionsFromCXX + lat.show (UINT_MAX); + cantProceed ("No compiler support for C++ exception"); +# else + throw lat; +# endif +} + +#endif // ifdef locationException_h +