From 1eb82ffb3dc368a9ebef5e2620ae5877da7daf5d Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Mon, 24 Jun 2024 10:33:14 +0100 Subject: [PATCH] Catch errors from callback. --- wrapper/Convert/SireOpenMM/pyqm.cpp | 50 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/wrapper/Convert/SireOpenMM/pyqm.cpp b/wrapper/Convert/SireOpenMM/pyqm.cpp index 74db8513a..4e7402e19 100644 --- a/wrapper/Convert/SireOpenMM/pyqm.cpp +++ b/wrapper/Convert/SireOpenMM/pyqm.cpp @@ -160,24 +160,44 @@ PyQMCallback::call( if (this->is_method) { - return bp::call_method>, QVector>>>( - this->py_object.ptr(), - this->name.toStdString().c_str(), - numbers_qm, - charges_mm, - xyz_qm, - xyz_mm - ); + try + { + return bp::call_method>, QVector>>>( + this->py_object.ptr(), + this->name.toStdString().c_str(), + numbers_qm, + charges_mm, + xyz_qm, + xyz_mm + ); + } + catch (const bp::error_already_set &) + { + PyErr_Print(); + throw SireError::process_error(QObject::tr( + "An error occurred when calling the QM Python callback method"), + CODELOC); + } } else { - return bp::call>, QVector>>>( - this->py_object.ptr(), - numbers_qm, - charges_mm, - xyz_qm, - xyz_mm - ); + try + { + return bp::call>, QVector>>>( + this->py_object.ptr(), + numbers_qm, + charges_mm, + xyz_qm, + xyz_mm + ); + } + catch (const bp::error_already_set &) + { + PyErr_Print(); + throw SireError::process_error(QObject::tr( + "An error occurred when calling the QM Python callback method"), + CODELOC); + } } }