certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] applications/PyHLA/hla/_rti exceptions.h


From: certi-cvs
Subject: [certi-cvs] applications/PyHLA/hla/_rti exceptions.h
Date: Thu, 06 Nov 2008 08:15:52 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Petr Gotthard <gotthardp>       08/11/06 08:15:52

Modified files:
        PyHLA/hla/_rti : exceptions.h 

Log message:
        Enhanced SetFromPyException() to include more decription in the 
exception.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/_rti/exceptions.h?cvsroot=certi&r1=1.1&r2=1.2

Patches:
Index: exceptions.h
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/_rti/exceptions.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- exceptions.h        25 Sep 2008 17:17:34 -0000      1.1
+++ exceptions.h        6 Nov 2008 08:15:51 -0000       1.2
@@ -11,13 +11,14 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
- * $Id: exceptions.h,v 1.1 2008/09/25 17:17:34 gotthardp Exp $
+ * $Id: exceptions.h,v 1.2 2008/11/06 08:15:51 gotthardp Exp $
  */
 
 #ifndef RTI_EXCEPTIONS_H
 #define RTI_EXCEPTIONS_H
 
 #include <RTI.hh>  
+#include <sstream>
 
 #include "module.h"
 
@@ -108,10 +109,36 @@
 template<class EXC>
 EXC SetFromPyException(PyObject *type)
 {
-    auto_decref<PyObject> strexception = PyObject_Str(PyErr_Occurred());
-    return EXC(PyString_AsString(strexception));
+    PyObject *exception, *value, *tb;
+    PyErr_Fetch(&exception, &value, &tb);
+    if (exception == NULL)
+        return EXC("unknown exception");
+
+    PyErr_NormalizeException(&exception, &value, &tb);
+    if (exception == NULL)
+        return EXC("unknown exception");
+
+    // FIXME: should be for debug only
+    PyErr_Display(exception, value, tb);
+
+    std::stringstream msg;
+    if (PyExceptionClass_Check(exception)) {
+        char* className = PyExceptionClass_Name(exception);
+        if (className != NULL)
+            msg << className;
+    }
+
+    PyObject *strvalue = PyObject_Str(value);
+    msg << ": " << PyString_AsString(strvalue);
+    Py_XDECREF(strvalue);
+
+    Py_XDECREF(exception);
+    Py_XDECREF(value);
+    Py_XDECREF(tb);
+
+    return EXC(msg.str().c_str());
 }
 
 #endif // RTI_EXCEPTIONS_H
 
-// $Id: exceptions.h,v 1.1 2008/09/25 17:17:34 gotthardp Exp $
+// $Id: exceptions.h,v 1.2 2008/11/06 08:15:51 gotthardp Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]