aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-04-17 14:49:57 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-05-07 21:10:45 +0200
commitd8ca812879ad70cd2aa914ea76cd529786deadc6 (patch)
tree97140467bca8c9bcda6f492ecb8598c9db136179 /sources/pyside6/libpysideqml
parentcffe2bc71d8e5d88efb879e6fe68c730e547fc4d (diff)
libshiboken: Add utility class for stashing Python errors
It encapsulates fetching/restoring errors and uses the old or new exception API depending on version. Task-number: PYSIDE-3067 Change-Id: I6e39d92c7e79fed864b364a90c5bd5b474a41ed6 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpysideqml')
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlmetacallerror.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmlmetacallerror.cpp b/sources/pyside6/libpysideqml/pysideqmlmetacallerror.cpp
index a3d2664c4..4e0afa3b2 100644
--- a/sources/pyside6/libpysideqml/pysideqmlmetacallerror.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlmetacallerror.cpp
@@ -5,6 +5,7 @@
#include <sbkpython.h>
#include <sbkstring.h>
+#include <sbkerrors.h>
#include <autodecref.h>
// Remove deprecated MACRO of copysign for MSVC #86286
@@ -40,17 +41,17 @@ std::optional<int> qmlMetaCallErrorHandler(QObject *object)
if (engine->currentStackFrame == nullptr)
return {};
- PyObject *errType{};
- PyObject *errValue{};
- PyObject *errTraceback{};
- PyErr_Fetch(&errType, &errValue, &errTraceback);
+ Shiboken::Errors::Stash errorStash;
+ PyObject *errValue = errorStash.getException();
// PYSIDE-464: The error is only valid before PyErr_Restore,
// PYSIDE-464: therefore we take local copies.
Shiboken::AutoDecRef objStr(PyObject_Str(errValue));
const QString errString = QString::fromUtf8(Shiboken::String::toCString(objStr));
- const bool isSyntaxError = errType == PyExc_SyntaxError;
- const bool isTypeError = errType == PyExc_TypeError;
- PyErr_Restore(errType, errValue, errTraceback);
+ const bool isSyntaxError = errValue != nullptr
+ && PyErr_GivenExceptionMatches(errValue, PyExc_SyntaxError);
+ const bool isTypeError = errValue != nullptr
+ && PyErr_GivenExceptionMatches(errValue, PyExc_TypeError);
+ errorStash.restore();
PyErr_Print(); // Note: PyErr_Print clears the error.