From cdecdb345b50ab2ca31846b76dad9ffd8b0f9cbc Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 2 Sep 2021 14:58:07 +0200 Subject: [PATCH] Register occ exceptions to python --- libsrc/occ/python_occ.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index 7f427ea6..36757bfb 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -101,9 +101,15 @@ DLL_HEADER void ExportNgOCC(py::module &m) ExportNgOCCBasic(m); ExportNgOCCShapes(m); - - // not working, since occ - exceptions don't derive from std::exception - // py::register_exception(m, "OCC-Exception"); + static py::exception exc(m, "OCCException"); + py::register_exception_translator([](std::exception_ptr p) + { + try { + if(p) std::rethrow_exception(p); + } catch (const Standard_Failure& e) { + exc((string(e.DynamicType()->Name()) + ": " + e.GetMessageString()).c_str()); + } + }); py::class_, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string") /*