mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
bpo-46328: Add sys.exception() (GH-30514)
This commit is contained in:
parent
9c2ebb906d
commit
c590b581bb
7 changed files with 147 additions and 19 deletions
|
@ -771,6 +771,28 @@ sys_excepthook_impl(PyObject *module, PyObject *exctype, PyObject *value,
|
|||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
sys.exception
|
||||
|
||||
Return the current exception.
|
||||
|
||||
Return the most recent exception caught by an except clause
|
||||
in the current stack frame or in an older stack frame, or None
|
||||
if no such exception exists.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
sys_exception_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=2381ee2f25953e40 input=c88fbb94b6287431]*/
|
||||
{
|
||||
_PyErr_StackItem *err_info = _PyErr_GetTopmostException(_PyThreadState_GET());
|
||||
if (err_info->exc_value != NULL) {
|
||||
return Py_NewRef(err_info->exc_value);
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
sys.exc_info
|
||||
|
||||
|
@ -1963,6 +1985,7 @@ static PyMethodDef sys_methods[] = {
|
|||
SYS__CURRENT_FRAMES_METHODDEF
|
||||
SYS__CURRENT_EXCEPTIONS_METHODDEF
|
||||
SYS_DISPLAYHOOK_METHODDEF
|
||||
SYS_EXCEPTION_METHODDEF
|
||||
SYS_EXC_INFO_METHODDEF
|
||||
SYS_EXCEPTHOOK_METHODDEF
|
||||
SYS_EXIT_METHODDEF
|
||||
|
@ -2457,7 +2480,8 @@ Functions:\n\
|
|||
\n\
|
||||
displayhook() -- print an object to the screen, and save it in builtins._\n\
|
||||
excepthook() -- print an exception and its traceback to sys.stderr\n\
|
||||
exc_info() -- return thread-safe information about the current exception\n\
|
||||
exception() -- return the current thread's active exception\n\
|
||||
exc_info() -- return information about the current thread's active exception\n\
|
||||
exit() -- exit the interpreter by raising SystemExit\n\
|
||||
getdlopenflags() -- returns flags to be used for dlopen() calls\n\
|
||||
getprofile() -- get the global profiling function\n\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue