]> 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>
Tue, 30 Sep 2008 16:21:43 +0000 (10:21 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Tue, 30 Sep 2008 16:21:43 +0000 (10:21 -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.

Catch std::exception to catch more printable exceptions. TextException is an
std::exception [child].

These changes were inspired by and required for eCAP.

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

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 f6c39d07442e28dc5a38dd5bf9e6567f5c2d0ff6..ff0412efdc0088e48105dcf7f78eb7bd7d19b69a 100644 (file)
@@ -566,7 +566,7 @@ void ICAPModXact::parseMore()
         parseBody();
 }
 
-void ICAPModXact::callException(const TextException &e)
+void ICAPModXact::callException(const std::exception &e)
 {
     if (!canStartBypass || isRetriable) {
         ICAPXaction::callException(e);
@@ -575,10 +575,10 @@ void ICAPModXact::callException(const TextException &e)
 
     try {
         debugs(93, 3, "bypassing ICAPModXact::" << inCall << " exception: " <<
-           e.message << ' ' << status());
+           e.what() << ' ' << status());
         bypassFailure();
     }
-    catch (const TextException &bypassE) {
+    catch (const std::exception &bypassE) {
         ICAPXaction::callException(bypassE);
     }
 }
index 9b60baa8662ff9d44932e9c92d0606c937b3aeb4..1c07fec3be64a9b7d39389b496fe009c05c8e892 100644 (file)
@@ -158,7 +158,7 @@ public:
 
 protected:
     // bypasses exceptions if needed and possible
-    virtual void callException(const TextException &e);
+    virtual void callException(const std::exception &e);
 
 private:
     virtual void start();
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
index 0db0fd268d25afeec7c691745c98a37dcefe579d..c940a4927d3996d6f273ce9d730729d62a3ba134 100644 (file)
@@ -62,8 +62,8 @@
 #define SQUID_EXIT_THROWING_CODE(status) \
        status = true; \
     } \
-    catch (const TextException &e) { \
-       debugs (11, 1, "Exception error:" << e.message); \
+    catch (const std::exception &e) { \
+       debugs (11, 1, "Exception error:" << e.what()); \
        status = false; \
     }