Struct cpython::PyErr
[−]
[src]
pub struct PyErr {
pub ptype: PyObject,
pub pvalue: Option<PyObject>,
pub ptraceback: Option<PyObject>,
}Represents a Python exception that was raised.
Fields
ptype: PyObject
The type of the exception. This should be either a PyClass or a PyType.
pvalue: Option<PyObject>
The value of the exception.
This can be either an instance of ptype,
a tuple of arguments to be passed to ptype's constructor,
or a single argument to be passed to ptype's constructor.
Call PyErr::instance() to get the exception instance in all cases.
ptraceback: Option<PyObject>
The PyTraceBack object associated with the error.
Methods
impl PyErr[src]
fn occurred(_: Python) -> bool
Gets whether an error is present in the Python interpreter's global state.
fn fetch(py: Python) -> PyErr
Retrieves the current error from the Python interpreter's global state.
The error is cleared from the Python interpreter.
If no error is set, returns a SystemError.
fn new<T, V>(py: Python, value: V) -> PyErr where T: PythonObjectWithTypeObject, V: ToPyObject
Creates a new PyErr of type T.
value can be:
* NoArgs: the exception instance will be created using python T()
* a tuple: the exception instance will be created using python T(*tuple)
* any other value: the exception instance will be created using python T(value)
Panics if T is not a python class derived from BaseException.
fn from_instance<O>(py: Python, obj: O) -> PyErr where O: PythonObject
Creates a new PyErr.
obj must be an Python exception instance, the PyErr will use that instance.
If obj is a Python exception type object, the PyErr will (lazily) create a new instance of that type.
Otherwise, a TypeError is created instead.
fn new_lazy_init(exc: PyType, value: Option<PyObject>) -> PyErr
Construct a new error, with the usual lazy initialization of Python exceptions.
exc is the exception type; usually one of the standard exceptions like PyExc::runtime_error().
value is the exception instance, or a tuple of arguments to pass to the exception constructor.
fn print(self, py: Python)
Print a standard traceback to sys.stderr.
fn print_and_set_sys_last_vars(self, py: Python)
Print a standard traceback to sys.stderr.
fn matches(&self, _py: Python, exc: &PyObject) -> bool
Return true if the current exception matches the exception in exc.
If exc is a class object, this also returns true when self is an instance of a subclass.
If exc is a tuple, all exceptions in the tuple (and recursively in subtuples) are searched for a match.
fn normalize(&mut self, py: Python)
Normalizes the error. This ensures that the exception value is an instance of the exception type.
fn get_type(&self, py: Python) -> PyType
Retrieves the exception type.
fn instance(&mut self, py: Python) -> PyObject
Retrieves the exception instance for this error.
This method takes &mut self because the error might need
to be normalized in order to create the exception instance.
fn restore(self, py: Python)
Writes the error back to the Python interpreter's global state.
This is the opposite of PyErr::fetch().
fn warn(py: Python, category: &PyObject, message: &str, stacklevel: i32) -> PyResult<()>
Issue a warning message. May return a PyErr if warnings-as-errors is enabled.
Trait Implementations
impl Debug for PyErr[src]
impl<'p> From<PythonObjectDowncastError<'p>> for PyErr[src]
Converts PythonObjectDowncastError to Python TypeError.