--------------------- PatchSet 9867 Date: 2010/06/08 08:27:40 Author: squidadm Branch: HEAD Tag: (none) Log: Add missing files TextException .cc .h Members: src/base/TextException.cc:INITIAL->1.1 src/base/TextException.h:INITIAL->1.1 --- /dev/null 2010-06-09 08:17:55.000000000 +0000 +++ squid3/src/base/TextException.cc 2010-06-09 08:17:55.408833304 +0000 @@ -0,0 +1,58 @@ +#include "config.h" +#include "base/TextException.h" +#include "Debug.h" +#include "util.h" + +TextException::TextException() +{ + message=NULL; + theFileName=NULL; + theLineNo=0; +} + +TextException::TextException(const TextException& right) : + message((right.message?xstrdup(right.message):NULL)), theFileName(right.theFileName), theLineNo(right.theLineNo) +{ +} + +TextException::TextException(const char *aMsg, const char *aFileName, int aLineNo): + message(xstrdup(aMsg)), theFileName(aFileName), theLineNo(aLineNo) +{} + +TextException::~TextException() throw() +{ + if (message) xfree(message); +} + +TextException& TextException::operator=(const TextException &right) +{ + if (this==&right) return *this; + if (message) xfree(message); + message=(right.message?xstrdup(right.message):NULL); + theFileName=right.theFileName; + theLineNo=right.theLineNo; + + return *this; +} + +const char *TextException::what() const throw() +{ + /// \todo add file:lineno + return message ? message : "TextException without a message"; +} + +void Throw(const char *message, const char *fileName, int lineNo) +{ + + // or should we let the exception recepient print the exception instead? + + if (fileName) { + debugs(0, 3, fileName << ':' << lineNo << ": exception" << + (message ? ": " : ".") << (message ? message : "")); + } else { + debugs(0, 3, "exception" << + (message ? ": " : ".") << (message ? message : "")); + } + + throw TextException(message, fileName, lineNo); +} --- /dev/null 2010-06-09 08:17:55.000000000 +0000 +++ squid3/src/base/TextException.h 2010-06-09 08:17:55.417207729 +0000 @@ -0,0 +1,52 @@ +#ifndef SQUID__TEXTEXCEPTION_H +#define SQUID__TEXTEXCEPTION_H + +// Origin: xstd/TextException + +#include "config.h" +#include + +// simple exception to report custom errors +// we may want to change the interface to be able to report system errors + +class TextException: public std::exception +{ + +public: + TextException(); + TextException(const char *aMessage, const char *aFileName = 0, int aLineNo = -1); + TextException(const TextException& right); + virtual ~TextException() throw(); + + virtual const char *what() const throw(); + + TextException& operator=(const TextException &right); + +public: + char *message; // read-only + +protected: + // optional location information + const char *theFileName; + int theLineNo; +}; + +//inline +//ostream &operator <<(ostream &os, const TextException &exx) { +// return exx.print(os); +//} + +#if !defined(TexcHere) +# define TexcHere(msg) TextException((msg), __FILE__, __LINE__) +#endif + +extern void Throw(const char *message, const char *fileName, int lineNo); + +// Must(condition) is like assert(condition) but throws an exception instead +#if !defined(Must) +# define Must(cond) ((cond) ? \ + (void)0 : \ + (void)Throw(#cond, __FILE__, __LINE__)) +#endif + +#endif /* SQUID__TEXTEXCEPTION_H */