summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index ab14770..0ff6a0d 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1200,6 +1200,33 @@ PyErr_Format(PyObject *exception, const char *format, ...)
}
+/* Adds a note to the current exception (if any) */
+void
+_PyErr_FormatNote(const char *format, ...)
+{
+ PyObject *exc = PyErr_GetRaisedException();
+ if (exc == NULL) {
+ return;
+ }
+ va_list vargs;
+ va_start(vargs, format);
+ PyObject *note = PyUnicode_FromFormatV(format, vargs);
+ va_end(vargs);
+ if (note == NULL) {
+ goto error;
+ }
+ int res = _PyException_AddNote(exc, note);
+ Py_DECREF(note);
+ if (res < 0) {
+ goto error;
+ }
+ PyErr_SetRaisedException(exc);
+ return;
+error:
+ _PyErr_ChainExceptions1(exc);
+}
+
+
PyObject *
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
{