summaryrefslogtreecommitdiffstats
path: root/Objects/exceptions.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-03-16 10:16:01 (GMT)
committerGitHub <noreply@github.com>2023-03-16 10:16:01 (GMT)
commit51d693c58454a2c525094a7c74ebac86859353fd (patch)
tree9c5bd67c259638864cc3e57031ead3707355ba8d /Objects/exceptions.c
parent2dc94634b50f0e5e207787e5ac1d56c68b22c3ae (diff)
downloadcpython-51d693c58454a2c525094a7c74ebac86859353fd.zip
cpython-51d693c58454a2c525094a7c74ebac86859353fd.tar.gz
cpython-51d693c58454a2c525094a7c74ebac86859353fd.tar.bz2
gh-102594: PyErr_SetObject adds note to exception raised on normalization error (#102675)
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r--Objects/exceptions.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index c6fb6a3..d69f740 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -3749,6 +3749,21 @@ _PyExc_Fini(PyInterpreterState *interp)
_PyExc_FiniTypes(interp);
}
+int
+_PyException_AddNote(PyObject *exc, PyObject *note)
+{
+ if (!PyExceptionInstance_Check(exc)) {
+ PyErr_Format(PyExc_TypeError,
+ "exc must be an exception, not '%s'",
+ Py_TYPE(exc)->tp_name);
+ return -1;
+ }
+ PyObject *r = BaseException_add_note(exc, note);
+ int res = r == NULL ? -1 : 0;
+ Py_XDECREF(r);
+ return res;
+}
+
/* Helper to do the equivalent of "raise X from Y" in C, but always using
* the current exception rather than passing one in.
*