Base: Improve Python exception handling
If the Python profiler is activated then transporting the dict as exception object is broken where InteractiveInterpreter::runCode() fails to restore it. To fix the problem use Exception::setPyException() instead inside the macto PY_CATCH and the generated wrapper code. This also improves exception handling in command line mode.
This commit is contained in:
@@ -446,12 +446,10 @@ BaseExport extern PyObject* PyExc_FC_AbortIOException;
|
||||
#define PY_TRY try
|
||||
|
||||
#define __PY_CATCH(R) \
|
||||
catch(Base::Exception &e) \
|
||||
catch(const Base::Exception &e) \
|
||||
{ \
|
||||
auto pye = e.getPyExceptionType(); \
|
||||
if(!pye) \
|
||||
pye = Base::PyExc_FC_GeneralError; \
|
||||
_Py_ErrorObj(R,pye,e.getPyObject()); \
|
||||
e.setPyException(); \
|
||||
R; \
|
||||
} \
|
||||
catch(const std::exception &e) \
|
||||
{ \
|
||||
|
||||
@@ -669,15 +669,12 @@ PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject
|
||||
-
|
||||
return ret;
|
||||
} // Please sync the following catch implementation with PY_CATCH
|
||||
catch(Base::Exception &e)
|
||||
catch(const Base::Exception& e)
|
||||
{
|
||||
auto pye = e.getPyExceptionType();
|
||||
if(!pye)
|
||||
pye = Base::PyExc_FC_GeneralError;
|
||||
PyErr_SetObject(pye, e.getPyObject());
|
||||
e.setPyException();
|
||||
return nullptr;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
|
||||
return nullptr;
|
||||
@@ -832,15 +829,12 @@ PyObject *@self.export.Name@::_getattr(const char *attr) // __getattr__ functi
|
||||
PyObject *r = getCustomAttributes(attr);
|
||||
if(r) return r;
|
||||
} // Please sync the following catch implementation with PY_CATCH
|
||||
catch(Base::Exception &e)
|
||||
catch(const Base::Exception& e)
|
||||
{
|
||||
auto pye = e.getPyExceptionType();
|
||||
if(!pye)
|
||||
pye = Base::PyExc_FC_GeneralError;
|
||||
PyErr_SetObject(pye, e.getPyObject());
|
||||
e.setPyException();
|
||||
return nullptr;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
|
||||
return nullptr;
|
||||
@@ -882,15 +876,12 @@ int @self.export.Name@::_setattr(const char *attr, PyObject *value) // __setattr
|
||||
else if (r == -1)
|
||||
return -1;
|
||||
} // Please sync the following catch implementation with PY_CATCH
|
||||
catch(Base::Exception &e)
|
||||
catch(const Base::Exception& e)
|
||||
{
|
||||
auto pye = e.getPyExceptionType();
|
||||
if(!pye)
|
||||
pye = Base::PyExc_FC_GeneralError;
|
||||
PyErr_SetObject(pye, e.getPyObject());
|
||||
e.setPyException();
|
||||
return -1;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user