summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-11-13 13:49:21 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-11-13 13:49:21 (GMT)
commit8b097b4ed726b8282fce582cb2c20ab9c986fc21 (patch)
treeca9b18d186c9132f62378e1bde87e766beb2b379 /Include
parent59799a83995f135bdb1b1a0994052c1f24c68e83 (diff)
downloadcpython-8b097b4ed726b8282fce582cb2c20ab9c986fc21.zip
cpython-8b097b4ed726b8282fce582cb2c20ab9c986fc21.tar.gz
cpython-8b097b4ed726b8282fce582cb2c20ab9c986fc21.tar.bz2
Close #17828: better handling of codec errors
- output type errors now redirect users to the type-neutral convenience functions in the codecs module - stateless errors that occur during encoding and decoding will now be automatically wrapped in exceptions that give the name of the codec involved
Diffstat (limited to 'Include')
-rw-r--r--Include/pyerrors.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 224567b..6a8e0e8 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -285,6 +285,28 @@ PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
const char *name, const char *doc, PyObject *base, PyObject *dict);
PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
+/* In exceptions.c */
+#ifndef Py_LIMITED_API
+/* Helper that attempts to replace the current exception with one of the
+ * same type but with a prefix added to the exception text. The resulting
+ * exception description looks like:
+ *
+ * prefix (exc_type: original_exc_str)
+ *
+ * Only some exceptions can be safely replaced. If the function determines
+ * it isn't safe to perform the replacement, it will leave the original
+ * unmodified exception in place.
+ *
+ * Returns a borrowed reference to the new exception (if any), NULL if the
+ * existing exception was left in place.
+ */
+PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
+ const char *prefix_format, /* ASCII-encoded string */
+ ...
+ );
+#endif
+
+
/* In sigcheck.c or signalmodule.c */
PyAPI_FUNC(int) PyErr_CheckSignals(void);
PyAPI_FUNC(void) PyErr_SetInterrupt(void);