Skip to content

Commit

Permalink
Tools: modify exception catch implemention in templateClassPyExport
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Aug 28, 2019
1 parent 22541cf commit 8ecee3c
Showing 1 changed file with 54 additions and 92 deletions.
146 changes: 54 additions & 92 deletions src/Tools/generateTemplates/templateClassPyExport.py
Expand Up @@ -547,54 +547,39 @@ class @self.export.Namespace@Export @self.export.Name@ : public @self.export.Fat
static_cast<@self.export.Name@*>(self)->startNotify();
-
return ret;
} // Please sync the following catch implementation with PY_CATCH
catch(Base::AbortException &e)
{
e.ReportException();
PyErr_SetObject(Base::BaseExceptionFreeCADAbort,e.getPyObject());
return NULL;
}
catch(Base::Exception& e) // catch the FreeCAD exceptions
catch(Base::Exception &e)
{
e.ReportException();
PyObject *edict = e.getPyObject();
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
Py_DECREF(edict);
auto pye = e.getPyExceptionType();
if(!pye)
pye = Base::BaseExceptionFreeCADError;
PyErr_SetObject(pye,e.getPyObject());
return NULL;
}
catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
catch(std::exception &e)
{
std::string str;
str += "File system exception thrown (";
//str += e.who();
//str += ", ";
str += e.what();
str += ")\\n";
Base::Console().Error(str.c_str());
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
PyErr_SetString(Base::BaseExceptionFreeCADError,e.what());
return NULL;
}
catch(const Py::Exception&)
{
// The exception text is already set
return NULL;
}
catch(const char* e) // catch simple string exceptions
catch(const char *e)
{
Base::Console().Error(e);
PyErr_SetString(Base::BaseExceptionFreeCADError,e);
return NULL;
}
// in debug not all exceptions will be caught to get the attention of the developer!
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(const std::exception& e) // catch other c++ exceptions
{
std::string str;
str += "FC++ exception thrown (";
str += e.what();
str += ")";
Base::Console().Error(str.c_str());
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
return NULL;
}
catch(...) // catch the rest!
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(...)
{
PyErr_SetString(Base::BaseExceptionFreeCADError,"Unknown C++ exception");
return NULL;
Expand Down Expand Up @@ -737,56 +722,44 @@ class @self.export.Namespace@Export @self.export.Name@ : public @self.export.Fat
// getter method for special Attributes (e.g. dynamic ones)
PyObject *r = getCustomAttributes(attr);
if(r) return r;
}
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(Base::Exception& e) // catch the FreeCAD exceptions
} // Please sync the following catch implementation with PY_CATCH
catch(Base::AbortException &e)
{
e.ReportException();
PyObject *edict = e.getPyObject();
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
Py_DECREF(edict);
PyErr_SetObject(Base::BaseExceptionFreeCADAbort,e.getPyObject());
return NULL;
}
catch(const std::exception& e) // catch other c++ exceptions
catch(Base::Exception &e)
{
std::string str;
str += "C++ exception thrown (";
str += e.what();
str += ")";
Base::Console().Error(str.c_str());
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
e.ReportException();
auto pye = e.getPyExceptionType();
if(!pye)
pye = Base::BaseExceptionFreeCADError;
PyErr_SetObject(pye,e.getPyObject());
return NULL;
}
catch(const Py::Exception&)
catch(std::exception &e)
{
// The exception text is already set
PyErr_SetString(Base::BaseExceptionFreeCADError,e.what());
return NULL;
}
catch(...) // catch the rest!
catch(const Py::Exception&)
{
PyErr_SetString(Base::BaseExceptionFreeCADError,"Unknown C++ exception");
// The exception text is already set
return NULL;
}
#else // DONT_CATCH_CXX_EXCEPTIONS
catch(Base::Exception& e) // catch the FreeCAD exceptions
catch(const char *e)
{
e.ReportException();
PyObject *edict = e.getPyObject();
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
Py_DECREF(edict);
PyErr_SetString(Base::BaseExceptionFreeCADError,e);
return NULL;
}
catch(const Py::Exception&)
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(...)
{
// The exception text is already set
PyErr_SetString(Base::BaseExceptionFreeCADError,"Unknown C++ exception");
return NULL;
}
#endif // DONT_CATCH_CXX_EXCEPTIONS
#endif
PyMethodDef *ml = Methods;
for (; ml->ml_name != NULL; ml++) {
Expand All @@ -811,55 +784,44 @@ class @self.export.Namespace@Export @self.export.Name@ : public @self.export.Fat
return 0;
else if (r == -1)
return -1;
}
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(Base::Exception& e) // catch the FreeCAD exceptions
} // Please sync the following catch implementation with PY_CATCH
catch(Base::AbortException &e)
{
e.ReportException();
PyObject *edict = e.getPyObject();
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
Py_DECREF(edict);
PyErr_SetObject(Base::BaseExceptionFreeCADAbort,e.getPyObject());
return -1;
}
catch(const std::exception& e) // catch other c++ exceptions
catch(Base::Exception &e)
{
std::string str;
str += "C++ exception thrown (";
str += e.what();
str += ")";
Base::Console().Error(str.c_str());
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
e.ReportException();
auto pye = e.getPyExceptionType();
if(!pye)
pye = Base::BaseExceptionFreeCADError;
PyErr_SetObject(pye,e.getPyObject());
return -1;
}
catch(const Py::Exception&)
catch(std::exception &e)
{
// The exception text is already set
PyErr_SetString(Base::BaseExceptionFreeCADError,e.what());
return -1;
}
catch(...) // catch the rest!
catch(const Py::Exception&)
{
PyErr_SetString(Base::BaseExceptionFreeCADError,"Unknown C++ exception");
// The exception text is already set
return -1;
}
#else // DONT_CATCH_CXX_EXCEPTIONS
catch(Base::Exception& e) // catch the FreeCAD exceptions
catch(const char *e)
{
e.ReportException();
PyObject *edict = e.getPyObject();
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
Py_DECREF(edict);
PyErr_SetString(Base::BaseExceptionFreeCADError,e);
return -1;
}
catch(const Py::Exception&)
#ifndef DONT_CATCH_CXX_EXCEPTIONS
catch(...)
{
// The exception text is already set
PyErr_SetString(Base::BaseExceptionFreeCADError,"Unknown C++ exception");
return -1;
}
#endif // DONT_CATCH_CXX_EXCEPTIONS
#endif
return @self.export.Father@::_setattr(attr, value);
}
Expand Down

0 comments on commit 8ecee3c

Please sign in to comment.