From: Alex Rousskov Date: Sun, 28 Sep 2008 01:16:18 +0000 (-0600) Subject: Made TextException a child of std::exception so that it is easier to catch X-Git-Tag: SQUID_3_1_0_1~45^2~11^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=acfd6800091e5a195a47d317384a624e51ca5d1a;p=thirdparty%2Fsquid.git Made TextException a child of std::exception so that it is easier to catch more exceptions (standard and custom) with one catch(). The catching code usually does not care what the exception is anyway. TextException needs more work to report more information in what() method. --- diff --git a/src/ICAP/AsyncJob.cc b/src/ICAP/AsyncJob.cc index 3f7b7439b7..f97454b98f 100644 --- a/src/ICAP/AsyncJob.cc +++ b/src/ICAP/AsyncJob.cc @@ -115,7 +115,7 @@ void AsyncJob::callStart(AsyncCall &call) typeName << " status in:" << status()); } -void AsyncJob::callException(const TextException &e) +void AsyncJob::callException(const std::exception &e) { // we must be called asynchronously and hence, the caller must lock us Must(cbdataReferenceValid(toCbdata())); @@ -212,9 +212,9 @@ JobDialer::dial(AsyncCall &call) try { doDial(); } - catch (const TextException &e) { + catch (const std::exception &e) { debugs(call.debugSection, 3, - HERE << call.name << " threw exception: " << e.message); + HERE << call.name << " threw exception: " << e.what()); job->callException(e); } diff --git a/src/ICAP/AsyncJob.h b/src/ICAP/AsyncJob.h index 6f3f635204..96a68450c9 100644 --- a/src/ICAP/AsyncJob.h +++ b/src/ICAP/AsyncJob.h @@ -30,7 +30,7 @@ * asynchronous calls. */ -class TextException; +class std::exception; /// \ingroup AsyncJobAPI class AsyncJob @@ -63,7 +63,7 @@ public: // asynchronous call maintenance bool canBeCalled(AsyncCall &call) const; void callStart(AsyncCall &call); - virtual void callException(const TextException &e); + virtual void callException(const std::exception &e); virtual void callEnd(); protected: diff --git a/src/TextException.cc b/src/TextException.cc index 3300e20d3a..ada4f5c6ba 100644 --- a/src/TextException.cc +++ b/src/TextException.cc @@ -5,11 +5,17 @@ TextException::TextException(const char *aMsg, const char *aFileName, int aLineN message(xstrdup(aMsg)), theFileName(aFileName), theLineNo(aLineNo) {} -TextException::~TextException() +TextException::~TextException() throw() { xfree(message); } +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) { diff --git a/src/TextException.h b/src/TextException.h index 3a78dadf2d..6e4ae9abb7 100644 --- a/src/TextException.h +++ b/src/TextException.h @@ -7,14 +7,14 @@ // simple exception to report custom errors // we may want to change the interface to be able to report system errors -class TextException +class TextException: public std::exception { public: TextException(const char *aMessage, const char *aFileName = 0, int aLineNo = -1); - ~TextException(); + virtual ~TextException() throw(); - // ostream &print(ostream &os) const; + virtual const char *what() const throw(); public: char *message; // read-only