mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 05:22:06 +00:00
Make sure C++ exceptions do not crash the Python interpreter
This commit is contained in:
@@ -282,6 +282,9 @@
|
|||||||
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, precision);
|
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, precision);
|
||||||
|
|
||||||
IfcGeom::BRepElement<double>* brep = kernel.create_brep_for_representation_and_product<double>(settings, representation, product);
|
IfcGeom::BRepElement<double>* brep = kernel.create_brep_for_representation_and_product<double>(settings, representation, product);
|
||||||
|
if (!brep) {
|
||||||
|
throw IfcParse::IfcException("Failed to process shape");
|
||||||
|
}
|
||||||
if (settings.use_brep_data()) {
|
if (settings.use_brep_data()) {
|
||||||
IfcGeom::SerializedElement<double>* serialization = new IfcGeom::SerializedElement<double>(*brep);
|
IfcGeom::SerializedElement<double>* serialization = new IfcGeom::SerializedElement<double>(*brep);
|
||||||
delete brep;
|
delete brep;
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ namespace IfcUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
%typemap(out) std::pair<IfcUtil::ArgumentType, Argument*> {
|
%typemap(out) std::pair<IfcUtil::ArgumentType, Argument*> {
|
||||||
|
// The SWIG %exception directive does not take care
|
||||||
|
// of our typemap. So the argument conversion block
|
||||||
|
// is wrapped in a try-catch block manually.
|
||||||
|
try {
|
||||||
const Argument& arg = *($1.second);
|
const Argument& arg = *($1.second);
|
||||||
const IfcUtil::ArgumentType type = $1.first;
|
const IfcUtil::ArgumentType type = $1.first;
|
||||||
if (arg.isNull() || type == IfcUtil::Argument_DERIVED) {
|
if (arg.isNull() || type == IfcUtil::Argument_DERIVED) {
|
||||||
@@ -164,6 +168,11 @@ namespace IfcUtil {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(IfcParse::IfcException& e) {
|
||||||
|
SWIG_exception(SWIG_RuntimeError, e.what());
|
||||||
|
} catch(...) {
|
||||||
|
SWIG_exception(SWIG_RuntimeError, "An unknown error occurred");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%extend IfcParse::IfcFile {
|
%extend IfcParse::IfcFile {
|
||||||
|
|||||||
Reference in New Issue
Block a user