]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Made TextException a child of std::exception so that it is easier to catch
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 28 Sep 2008 01:16:18 +0000 (19:16 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 28 Sep 2008 01:16:18 +0000 (19:16 -0600)
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.

src/ICAP/AsyncJob.cc
src/ICAP/AsyncJob.h
src/TextException.cc
src/TextException.h

index 3f7b7439b79024d6db02350e8f98f457d994acd6..f97454b98fef2d7b1bd22c5a663384262758e212 100644 (file)
@@ -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);
     }
 
index 6f3f6352048baf26ee53b31aa2ecf18c2c84d744..96a68450c9a53d60697e270fafdbdb425a45dafe 100644 (file)
@@ -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:
index 3300e20d3a1a509ebfe1823177f21f342d134fbd..ada4f5c6baabea10fb15add8ab1e6df509b5707c 100644 (file)
@@ -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)
 {
 
index 3a78dadf2d3e59c7b883e987176239f14394e545..6e4ae9abb712510620f2ad8bd4798ff9b0d34698 100644 (file)
@@ -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