diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index e6baccd381..775685912e 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -39,6 +39,8 @@ #include "PyObjectBase.h" #include +#include "ExceptionFactory.h" + char format2[1024]; //Warning! Can't go over 512 characters!!! unsigned int format2_len = 1024; @@ -82,6 +84,52 @@ PyException::~PyException() throw() { } +void PyException::ThrowException(void) +{ + PyException myexcp = PyException(); + + if(PP_PyDict_Object!=NULL) { + + Base::ExceptionInfo info; + + PyObject *pystring; + + pystring = PyDict_GetItemString(PP_PyDict_Object,"sclassname"); + + if(pystring==NULL) + throw myexcp; + + info.exceptionname = std::string(PyString_AsString(pystring)); + + if(!Base::ExceptionFactory::Instance().CanProduce(info.exceptionname.c_str())) + throw myexcp; + + pystring = PyDict_GetItemString(PP_PyDict_Object,"sfile"); + + if(pystring!=NULL) + info.file = std::string(PyString_AsString(pystring)); + + pystring = PyDict_GetItemString(PP_PyDict_Object,"sfunction"); + + if(pystring!=NULL) + info.function = std::string(PyString_AsString(pystring)); + + pystring = PyDict_GetItemString(PP_PyDict_Object,"sErrMsg"); + + if(pystring!=NULL) + info.message = std::string(PyString_AsString(pystring)); + + pystring = PyDict_GetItemString(PP_PyDict_Object,"iline"); + + if(pystring!=NULL) + info.line = PyInt_AsLong(pystring); + + Base::ExceptionFactory::Instance().raiseException(info); + } + else + throw myexcp; +} + void PyException::ReportException (void) const { Base::Console().Error("%s%s: %s\n", @@ -197,8 +245,10 @@ std::string InterpreterSingleton::runString(const char *sCmd) if (!presult) { if (PyErr_ExceptionMatches(PyExc_SystemExit)) throw SystemExitException(); - else - throw PyException(); + else { + PyException::ThrowException(); + //throw PyException(); + } } PyObject* repr = PyObject_Repr(presult); diff --git a/src/Base/Interpreter.h b/src/Base/Interpreter.h index c11f65f36b..f7d57b4d44 100644 --- a/src/Base/Interpreter.h +++ b/src/Base/Interpreter.h @@ -53,7 +53,6 @@ #include "Exception.h" - namespace Base { using std::string; @@ -67,6 +66,11 @@ public: /// constructor does the whole job PyException(void); ~PyException() throw(); + + /// this method determines if the original exception + /// can be reconstructed or not, if yes throws the reconstructed version + /// if not, throws a generic PyException. + static void ThrowException(void); /// this function returns the stack trace const std::string &getStackTrace(void) const {return _stackTrace;}