[][src]Struct pyo3::PyErr

pub struct PyErr {
    pub ptype: Py<PyType>,
    pub pvalue: PyErrValue,
    pub ptraceback: Option<PyObject>,
}

Represents a Python exception that was raised.

Fields

ptype: Py<PyType>

The type of the exception. This should be either a PyClass or a PyType.

pvalue: PyErrValue

The value of the exception.

This can be either an instance of PyObject, 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]

pub fn new<T, V>(value: V) -> PyErr where
    T: PyTypeObject,
    V: ToPyObject + 'static, 
[src]

Creates a new PyErr of type T.

value can be:

  • 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.

Example: return Err(PyErr::new::<exceptions::TypeError, _>("Error message"));

pub fn from_type<A>(exc: Py<PyType>, args: A) -> PyErr where
    A: ToPyObject + 'static, 
[src]

Construct a new error, with the usual lazy initialization of Python exceptions. exc is the exception type; usually one of the standard exceptions like exceptions::RuntimeError. args is the a tuple of arguments to pass to the exception constructor.

pub fn from_value<T>(value: PyErrValue) -> PyErr where
    T: PyTypeObject
[src]

Creates a new PyErr of type T.

pub fn from_instance(obj: &PyAny) -> PyErr[src]

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.

pub fn occurred(_: Python) -> bool[src]

Gets whether an error is present in the Python interpreter's global state.

pub fn fetch(_: Python) -> PyErr[src]

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.

pub fn new_type<'p>(
    _: Python<'p>,
    name: &str,
    base: Option<&PyType>,
    dict: Option<PyObject>
) -> *mut PyTypeObject
[src]

Creates a new exception type with the given name, which must be of the form <module>.<ExceptionName>, as required by PyErr_NewException.

base can be an existing exception type to subclass, or a tuple of classes dict specifies an optional dictionary of class variables and methods

pub fn print(self, py: Python)[src]

Print a standard traceback to sys.stderr.

pub fn print_and_set_sys_last_vars(self, py: Python)[src]

Print a standard traceback to sys.stderr.

pub fn matches<T>(&self, py: Python, exc: T) -> bool where
    T: ToBorrowedObject
[src]

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.

pub fn is_instance<T>(&self, _py: Python) -> bool where
    T: PyTypeObject
[src]

Return true if the current exception is instance of T

pub fn normalize(&mut self, py: Python)[src]

Normalizes the error. This ensures that the exception value is an instance of the exception type.

pub fn restore(self, py: Python)[src]

Writes the error back to the Python interpreter's global state. This is the opposite of PyErr::fetch().

pub fn warn(
    py: Python,
    category: &PyAny,
    message: &str,
    stacklevel: i32
) -> PyResult<()>
[src]

Issue a warning message. May return a PyErr if warnings-as-errors is enabled.

pub fn clone_ref(&self, py: Python) -> PyErr[src]

Trait Implementations

impl ToPyObject for PyErr[src]

impl FromPy<PyErr> for PyObject[src]

impl<'a> IntoPy<PyObject> for &'a PyErr[src]

impl<T> Into<Result<T, PyErr>> for PyErr[src]

Convert PyErr to PyResult<T>

impl From<PyDowncastError> for PyErr[src]

Converts PyDowncastError to Python TypeError.

impl From<PyErr> for Error[src]

Convert PyErr to io::Error

impl From<Error> for PyErr[src]

Create OSError from io::Error

impl<W: 'static + Send + Debug> From<IntoInnerError<W>> for PyErr[src]

impl From<TryFromSliceError> for PyErr[src]

impl From<ParseIntError> for PyErr[src]

impl From<ParseFloatError> for PyErr[src]

impl From<TryFromIntError> for PyErr[src]

impl From<Infallible> for PyErr[src]

impl From<ParseBoolError> for PyErr[src]

impl From<IntoStringError> for PyErr[src]

impl From<NulError> for PyErr[src]

impl From<Utf8Error> for PyErr[src]

impl From<FromUtf8Error> for PyErr[src]

impl From<FromUtf16Error> for PyErr[src]

impl From<DecodeUtf16Error> for PyErr[src]

impl From<AddrParseError> for PyErr[src]

impl From<BaseException> for PyErr[src]

impl From<Exception> for PyErr[src]

impl From<StopAsyncIteration> for PyErr[src]

impl From<StopIteration> for PyErr[src]

impl From<GeneratorExit> for PyErr[src]

impl From<ArithmeticError> for PyErr[src]

impl From<LookupError> for PyErr[src]

impl From<AssertionError> for PyErr[src]

impl From<AttributeError> for PyErr[src]

impl From<BufferError> for PyErr[src]

impl From<EOFError> for PyErr[src]

impl From<FloatingPointError> for PyErr[src]

impl From<OSError> for PyErr[src]

impl From<ImportError> for PyErr[src]

impl From<ModuleNotFoundError> for PyErr[src]

impl From<IndexError> for PyErr[src]

impl From<KeyError> for PyErr[src]

impl From<KeyboardInterrupt> for PyErr[src]

impl From<MemoryError> for PyErr[src]

impl From<NameError> for PyErr[src]

impl From<OverflowError> for PyErr[src]

impl From<RuntimeError> for PyErr[src]

impl From<RecursionError> for PyErr[src]

impl From<NotImplementedError> for PyErr[src]

impl From<SyntaxError> for PyErr[src]

impl From<ReferenceError> for PyErr[src]

impl From<SystemError> for PyErr[src]

impl From<SystemExit> for PyErr[src]

impl From<TypeError> for PyErr[src]

impl From<UnboundLocalError> for PyErr[src]

impl From<UnicodeError> for PyErr[src]

impl From<UnicodeDecodeError> for PyErr[src]

impl From<UnicodeEncodeError> for PyErr[src]

impl From<UnicodeTranslateError> for PyErr[src]

impl From<ValueError> for PyErr[src]

impl From<ZeroDivisionError> for PyErr[src]

impl From<BlockingIOError> for PyErr[src]

impl From<BrokenPipeError> for PyErr[src]

impl From<ChildProcessError> for PyErr[src]

impl From<ConnectionError> for PyErr[src]

impl From<ConnectionAbortedError> for PyErr[src]

impl From<ConnectionRefusedError> for PyErr[src]

impl From<ConnectionResetError> for PyErr[src]

impl From<FileExistsError> for PyErr[src]

impl From<FileNotFoundError> for PyErr[src]

impl From<InterruptedError> for PyErr[src]

impl From<IsADirectoryError> for PyErr[src]

impl From<NotADirectoryError> for PyErr[src]

impl From<PermissionError> for PyErr[src]

impl From<ProcessLookupError> for PyErr[src]

impl From<TimeoutError> for PyErr[src]

impl From<EnvironmentError> for PyErr[src]

impl From<IOError> for PyErr[src]

impl From<CancelledError> for PyErr[src]

impl From<InvalidStateError> for PyErr[src]

impl From<TimeoutError> for PyErr[src]

impl From<IncompleteReadError> for PyErr[src]

impl From<LimitOverrunError> for PyErr[src]

impl From<QueueEmpty> for PyErr[src]

impl From<QueueFull> for PyErr[src]

impl From<herror> for PyErr[src]

impl From<gaierror> for PyErr[src]

impl From<timeout> for PyErr[src]

impl Debug for PyErr[src]

Auto Trait Implementations

impl !Send for PyErr

impl !Sync for PyErr

impl Unpin for PyErr

impl !UnwindSafe for PyErr

impl !RefUnwindSafe for PyErr

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]