Issue #28410: Added _PyErr_FormatFromCause() -- the helper for raising

new exception with setting current exception as __cause__.

_PyErr_FormatFromCause(exception, format, args...) is equivalent to Python

    raise exception(format % args) from sys.exc_info()[1]
This commit is contained in:
Serhiy Storchaka 2016-10-21 17:09:17 +03:00
parent b0426cd8c4
commit 467ab194fc
7 changed files with 70 additions and 53 deletions

View file

@ -3835,13 +3835,10 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
Py_FileSystemDefaultEncodeErrors);
#ifdef MS_WINDOWS
if (!res && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
PyErr_Format(PyExc_RuntimeError,
"filesystem path bytes were not correctly encoded with '%s'. " \
_PyErr_FormatFromCause(PyExc_RuntimeError,
"filesystem path bytes were not correctly encoded with '%s'. "
"Please report this at http://bugs.python.org/issue27781",
Py_FileSystemDefaultEncoding);
_PyErr_ChainExceptions(exc, val, tb);
}
#endif
return res;