Date: Friday, November 25, 2005 @ 16:10:58
  Author: marc
    Path: /cvsroot/carob/carob

Modified: include/CarobException.hpp (1.9 -> 1.10) src/CarobException.cpp
          (1.7 -> 1.8)

Implemented local backTrace #ifdef __GLIBC__


----------------------------+
 include/CarobException.hpp |   39 ++++++++++++++++++++++++++++++++++++---
 src/CarobException.cpp     |   25 ++++++++++++++++++++++---
 2 files changed, 58 insertions(+), 6 deletions(-)


Index: carob/include/CarobException.hpp
diff -u carob/include/CarobException.hpp:1.9 
carob/include/CarobException.hpp:1.10
--- carob/include/CarobException.hpp:1.9        Wed Sep 21 15:39:13 2005
+++ carob/include/CarobException.hpp    Fri Nov 25 16:10:58 2005
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
+ * Contributor(s): Marc Herbert
  */
 
 #ifndef _CAROBEXCEPTION_H_
@@ -32,6 +32,21 @@
 class DriverSocket;
 using namespace std;
 
+#ifdef __GLIBC__  // from features.h
+#define GLIB_BACKTRACE
+#include <execinfo.h>
+#include <stdlib.h>
+#endif // __GLIBC__
+
+// TODO: convert this to wstring (for uniformity reasons)
+typedef vector<string> BackTrace;
+
+
+// TODO: replace this by a vector of actual objects, so we can
+// delete our custom copiers and destructors. No need for
+// performance here, cause exceptions are not on the critical path.
+typedef vector<StackTraceElement*> StackTrace;
+
 /**
  * Mother class of all exceptions send by the driver defining common exception 
  * interface.
@@ -76,17 +91,31 @@
 
   /** Gets the exception error message */
   virtual wstring        description() const { return message; }
+
+  /** Returns the remote java stack trace */
+  const StackTrace getStackTrace() const { return stackTrace; }
+
+  /** Returns the local stack trace */
+  const BackTrace getBackTrace() const { return backTrace; }
+
+  /** Returns a reference to the next exception in the chain, NULL if tail */
+  const CarobException* getNext() const { return causePtr; }
+
+  const BackTrace             backTrace;
+
 protected:
   /** Error message */
   wstring                     message;
   /** Stack trace as a vector of traces */
-  vector<StackTraceElement*>  stackTrace;
+  StackTrace                  stackTrace;
   /** pointer to the exception that generated this one */
   CarobException*             causePtr;
   /** SQL error message */
   wstring                     SQLState;
   /** Vendor-specific error code */
   int32_t                     errorCode;
+private:
+  CarobException & operator =( CarobException & forbidden);
 };
 
 /**
@@ -221,6 +250,9 @@
    */
   BackendException(const DriverSocket& sock) throw (SocketIOException,
       UnexpectedException) : CarobException(sock) {};
+
+  const wstring & getSQLState() const { return SQLState; }
+
 };
 
 /**
@@ -274,7 +306,8 @@
    * Copy constructor
    */
   StackTraceElement(const StackTraceElement& st);
-private:
+public:
+// private: TODO: set them const?
   wstring declaringClass;
   wstring methodName;
   wstring fileName;
Index: carob/src/CarobException.cpp
diff -u carob/src/CarobException.cpp:1.7 carob/src/CarobException.cpp:1.8
--- carob/src/CarobException.cpp:1.7    Tue Oct 18 17:55:55 2005
+++ carob/src/CarobException.cpp        Fri Nov 25 16:10:58 2005
@@ -22,6 +22,24 @@
 #include "CarobException.hpp"
 #include "DriverSocket.hpp"
 
+/** constructs the BackTrace of the current place */
+static BackTrace currentBackTrace()
+{
+  BackTrace bt;
+
+#ifdef GLIB_BACKTRACE
+  void * stack_pointers[100];
+  size_t size = backtrace (stack_pointers /* set it */, 100);
+  char **cstrings = backtrace_symbols (stack_pointers /* use it */, size);
+  for (size_t i=0; i<size; i++)
+    bt.push_back(cstrings[i]);
+  free(cstrings);
+#endif
+
+  return bt;
+}
+
+
 CarobException::~CarobException()
 {
   if (causePtr != NULL)
@@ -36,7 +54,7 @@
   }
 }
 
-CarobException::CarobException(const CarobException& ce)
+CarobException::CarobException(const CarobException& ce) : 
backTrace(ce.backTrace)
 {
   message = ce.message;
   for (size_t i=0; i<ce.stackTrace.size(); i++)
@@ -55,7 +73,7 @@
   errorCode = ce.errorCode;
 }
 
-CarobException::CarobException(const DriverSocket& sock)
+CarobException::CarobException(const DriverSocket& sock) : 
backTrace(currentBackTrace())
 {
   bool hasNextException;
 
@@ -78,7 +96,7 @@
 }
 
 CarobException::CarobException(const wstring &messagePrm,
-    CarobException* causePrm)
+                              CarobException* causePrm) : 
backTrace(currentBackTrace())
 {
   message = messagePrm;
   causePtr = causePrm;
@@ -103,6 +121,7 @@
   ds>>lineNumber;
 }
 
+// is this useful?
 StackTraceElement::StackTraceElement(const StackTraceElement& st)
 {
   declaringClass = st.declaringClass;

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to