pub struct PyErr { /* private fields */ }
Expand description
Represents a Python exception.
To avoid needing access to Python
in Into
conversions to create PyErr
(thus improving
compatibility with ?
and other Rust errors) this type supports creating exceptions instances
in a lazy fashion, where the full Python object for the exception is created only when needed.
Accessing the contained exception in any way, such as with value
,
get_type
, or is_instance
will create the full
exception object if it was not already created.
Implementations§
source§impl PyErr
impl PyErr
sourcepub fn new<T, A>(args: A) -> PyErr
pub fn new<T, A>(args: A) -> PyErr
Creates a new PyErr of type T
.
args
can be:
- a tuple: the exception instance will be created using the equivalent to the Python
expression
T(*tuple)
- any other value: the exception instance will be created using the equivalent to the Python
expression
T(value)
This exception instance will be initialized lazily. This avoids the need for the Python GIL
to be held, but requires args
to be Send
and Sync
. If args
is not Send
or Sync
,
consider using PyErr::from_value
instead.
If T
does not inherit from BaseException
, then a TypeError
will be returned.
If calling T’s constructor with args
raises an exception, that exception will be returned.
§Examples
use pyo3::prelude::*;
use pyo3::exceptions::PyTypeError;
#[pyfunction]
fn always_throws() -> PyResult<()> {
Err(PyErr::new::<PyTypeError, _>("Error message"))
}
In most cases, you can use a concrete exception’s constructor instead:
use pyo3::prelude::*;
use pyo3::exceptions::PyTypeError;
#[pyfunction]
fn always_throws() -> PyResult<()> {
Err(PyTypeError::new_err("Error message"))
}
sourcepub fn from_type<A>(ty: &PyType, args: A) -> PyErr
pub fn from_type<A>(ty: &PyType, args: A) -> PyErr
Deprecated form of PyErr::from_type_bound
sourcepub fn from_type_bound<A>(ty: Bound<'_, PyType>, args: A) -> PyErr
pub fn from_type_bound<A>(ty: Bound<'_, PyType>, args: A) -> PyErr
Constructs a new PyErr from the given Python type and arguments.
ty
is the exception type; usually one of the standard exceptions
like exceptions::PyRuntimeError
.
args
is either a tuple or a single value, with the same meaning as in PyErr::new
.
If ty
does not inherit from BaseException
, then a TypeError
will be returned.
If calling ty
with args
raises an exception, that exception will be returned.
sourcepub fn from_value(obj: &PyAny) -> PyErr
pub fn from_value(obj: &PyAny) -> PyErr
Deprecated form of PyErr::from_value_bound
.
sourcepub fn from_value_bound(obj: Bound<'_, PyAny>) -> PyErr
pub fn from_value_bound(obj: Bound<'_, PyAny>) -> PyErr
Creates a new PyErr.
If obj
is a Python exception object, the PyErr will contain that object.
If obj
is a Python exception type object, this is equivalent to PyErr::from_type(obj, ())
.
Otherwise, a TypeError
is created.
§Examples
use pyo3::prelude::*;
use pyo3::PyTypeInfo;
use pyo3::exceptions::PyTypeError;
use pyo3::types::PyString;
Python::with_gil(|py| {
// Case #1: Exception object
let err = PyErr::from_value_bound(PyTypeError::new_err("some type error")
.value_bound(py).clone().into_any());
assert_eq!(err.to_string(), "TypeError: some type error");
// Case #2: Exception type
let err = PyErr::from_value_bound(PyTypeError::type_object_bound(py).into_any());
assert_eq!(err.to_string(), "TypeError: ");
// Case #3: Invalid exception value
let err = PyErr::from_value_bound(PyString::new_bound(py, "foo").into_any());
assert_eq!(
err.to_string(),
"TypeError: exceptions must derive from BaseException"
);
});
sourcepub fn get_type<'py>(&'py self, py: Python<'py>) -> &'py PyType
pub fn get_type<'py>(&'py self, py: Python<'py>) -> &'py PyType
Deprecated form of PyErr::get_type_bound
.
sourcepub fn get_type_bound<'py>(&self, py: Python<'py>) -> Bound<'py, PyType>
pub fn get_type_bound<'py>(&self, py: Python<'py>) -> Bound<'py, PyType>
Returns the type of this exception.
§Examples
use pyo3::{prelude::*, exceptions::PyTypeError, types::PyType};
Python::with_gil(|py| {
let err: PyErr = PyTypeError::new_err(("some type error",));
assert!(err.get_type_bound(py).is(&PyType::new_bound::<PyTypeError>(py)));
});
sourcepub fn value<'py>(&'py self, py: Python<'py>) -> &'py PyBaseException
pub fn value<'py>(&'py self, py: Python<'py>) -> &'py PyBaseException
Deprecated form of PyErr::value_bound
.
sourcepub fn value_bound<'py>(&self, py: Python<'py>) -> &Bound<'py, PyBaseException>
pub fn value_bound<'py>(&self, py: Python<'py>) -> &Bound<'py, PyBaseException>
Returns the value of this exception.
§Examples
use pyo3::{exceptions::PyTypeError, PyErr, Python};
Python::with_gil(|py| {
let err: PyErr = PyTypeError::new_err(("some type error",));
assert!(err.is_instance_of::<PyTypeError>(py));
assert_eq!(err.value_bound(py).to_string(), "some type error");
});
sourcepub fn into_value(self, py: Python<'_>) -> Py<PyBaseException>
pub fn into_value(self, py: Python<'_>) -> Py<PyBaseException>
Consumes self to take ownership of the exception value contained in this error.
sourcepub fn traceback<'py>(&'py self, py: Python<'py>) -> Option<&'py PyTraceback>
pub fn traceback<'py>(&'py self, py: Python<'py>) -> Option<&'py PyTraceback>
Deprecated form of PyErr::traceback_bound
.
sourcepub fn traceback_bound<'py>(
&self,
py: Python<'py>
) -> Option<Bound<'py, PyTraceback>>
pub fn traceback_bound<'py>( &self, py: Python<'py> ) -> Option<Bound<'py, PyTraceback>>
Returns the traceback of this exception object.
§Examples
use pyo3::{exceptions::PyTypeError, Python};
Python::with_gil(|py| {
let err = PyTypeError::new_err(("some type error",));
assert!(err.traceback_bound(py).is_none());
});
sourcepub fn occurred(_: Python<'_>) -> bool
pub fn occurred(_: Python<'_>) -> bool
Gets whether an error is present in the Python interpreter’s global state.
sourcepub fn take(py: Python<'_>) -> Option<PyErr>
pub fn take(py: Python<'_>) -> Option<PyErr>
Takes the current error from the Python interpreter’s global state and clears the global
state. If no error is set, returns None
.
If the error is a PanicException
(which would have originated from a panic in a pyo3
callback) then this function will resume the panic.
Use this function when it is not known if an error should be present. If the error is
expected to have been set, for example from PyErr::occurred
or by an error return value
from a C FFI function, use PyErr::fetch
.
sourcepub fn fetch(py: Python<'_>) -> PyErr
pub fn fetch(py: Python<'_>) -> PyErr
Equivalent to PyErr::take, but when no error is set:
- Panics in debug mode.
- Returns a
SystemError
in release mode.
This behavior is consistent with Python’s internal handling of what happens when a C return value indicates an error occurred but the global error state is empty. (A lack of exception should be treated as a bug in the code which returned an error code but did not set an exception.)
Use this function when the error is expected to have been set, for example from PyErr::occurred or by an error return value from a C FFI function.
sourcepub fn new_type(
py: Python<'_>,
name: &str,
doc: Option<&str>,
base: Option<&PyType>,
dict: Option<PyObject>
) -> PyResult<Py<PyType>>
pub fn new_type( py: Python<'_>, name: &str, doc: Option<&str>, base: Option<&PyType>, dict: Option<PyObject> ) -> PyResult<Py<PyType>>
Deprecated form of PyErr::new_type_bound
sourcepub fn new_type_bound<'py>(
py: Python<'py>,
name: &str,
doc: Option<&str>,
base: Option<&Bound<'py, PyType>>,
dict: Option<PyObject>
) -> PyResult<Py<PyType>>
pub fn new_type_bound<'py>( py: Python<'py>, name: &str, doc: Option<&str>, base: Option<&Bound<'py, PyType>>, dict: Option<PyObject> ) -> PyResult<Py<PyType>>
Creates a new exception type with the given name and docstring.
base
can be an existing exception type to subclass, or a tuple of classes.dict
specifies an optional dictionary of class variables and methods.doc
will be the docstring seen by python users.
§Errors
This function returns an error if name
is not of the form <module>.<ExceptionName>
.
§Panics
This function will panic if name
or doc
cannot be converted to CString
s.
sourcepub fn print(&self, py: Python<'_>)
pub fn print(&self, py: Python<'_>)
Calls sys.excepthook
and then prints a standard traceback to sys.stderr
.
sourcepub fn print_and_set_sys_last_vars(&self, py: Python<'_>)
pub fn print_and_set_sys_last_vars(&self, py: Python<'_>)
Calls sys.excepthook
and then prints a standard traceback to sys.stderr
.
Additionally sets sys.last_{type,value,traceback,exc}
attributes to this exception.
sourcepub fn matches<T>(&self, py: Python<'_>, exc: T) -> boolwhere
T: ToPyObject,
pub fn matches<T>(&self, py: Python<'_>, exc: T) -> boolwhere
T: ToPyObject,
Returns 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.
sourcepub fn is_instance(&self, py: Python<'_>, ty: &PyAny) -> bool
pub fn is_instance(&self, py: Python<'_>, ty: &PyAny) -> bool
Deprecated form of PyErr::is_instance_bound
.
sourcepub fn is_instance_bound(&self, py: Python<'_>, ty: &Bound<'_, PyAny>) -> bool
pub fn is_instance_bound(&self, py: Python<'_>, ty: &Bound<'_, PyAny>) -> bool
Returns true if the current exception is instance of T
.
sourcepub fn is_instance_of<T>(&self, py: Python<'_>) -> boolwhere
T: PyTypeInfo,
pub fn is_instance_of<T>(&self, py: Python<'_>) -> boolwhere
T: PyTypeInfo,
Returns true if the current exception is instance of T
.
sourcepub fn restore(self, py: Python<'_>)
pub fn restore(self, py: Python<'_>)
Writes the error back to the Python interpreter’s global state.
This is the opposite of PyErr::fetch()
.
sourcepub fn write_unraisable(self, py: Python<'_>, obj: Option<&PyAny>)
pub fn write_unraisable(self, py: Python<'_>, obj: Option<&PyAny>)
Deprecated form of PyErr::write_unraisable_bound
.
sourcepub fn write_unraisable_bound(
self,
py: Python<'_>,
obj: Option<&Bound<'_, PyAny>>
)
pub fn write_unraisable_bound( self, py: Python<'_>, obj: Option<&Bound<'_, PyAny>> )
Reports the error as unraisable.
This calls sys.unraisablehook()
using the current exception and obj argument.
This method is useful to report errors in situations where there is no good mechanism to report back to the Python land. In Python this is used to indicate errors in background threads or destructors which are protected. In Rust code this is commonly useful when you are calling into a Python callback which might fail, but there is no obvious way to handle this error other than logging it.
Calling this method has the benefit that the error goes back into a standardized callback
in Python which for instance allows unittests to ensure that no unraisable error
actually happend by hooking sys.unraisablehook
.
Example:
Python::with_gil(|py| {
match failing_function() {
Err(pyerr) => pyerr.write_unraisable_bound(py, None),
Ok(..) => { /* do something here */ }
}
Ok(())
})
sourcepub fn warn(
py: Python<'_>,
category: &PyAny,
message: &str,
stacklevel: i32
) -> PyResult<()>
pub fn warn( py: Python<'_>, category: &PyAny, message: &str, stacklevel: i32 ) -> PyResult<()>
Deprecated form of PyErr::warn_bound
.
sourcepub fn warn_bound<'py>(
py: Python<'py>,
category: &Bound<'py, PyAny>,
message: &str,
stacklevel: i32
) -> PyResult<()>
pub fn warn_bound<'py>( py: Python<'py>, category: &Bound<'py, PyAny>, message: &str, stacklevel: i32 ) -> PyResult<()>
Issues a warning message.
May return an Err(PyErr)
if warnings-as-errors is enabled.
Equivalent to warnings.warn()
in Python.
The category
should be one of the Warning
classes available in
pyo3::exceptions
, or a subclass. The Python
object can be retrieved using Python::get_type()
.
Example:
Python::with_gil(|py| {
let user_warning = py.get_type_bound::<pyo3::exceptions::PyUserWarning>();
PyErr::warn_bound(py, &user_warning, "I am warning you", 0)?;
Ok(())
})
sourcepub fn warn_explicit(
py: Python<'_>,
category: &PyAny,
message: &str,
filename: &str,
lineno: i32,
module: Option<&str>,
registry: Option<&PyAny>
) -> PyResult<()>
pub fn warn_explicit( py: Python<'_>, category: &PyAny, message: &str, filename: &str, lineno: i32, module: Option<&str>, registry: Option<&PyAny> ) -> PyResult<()>
Deprecated form of PyErr::warn_explicit_bound
.
sourcepub fn warn_explicit_bound<'py>(
py: Python<'py>,
category: &Bound<'py, PyAny>,
message: &str,
filename: &str,
lineno: i32,
module: Option<&str>,
registry: Option<&Bound<'py, PyAny>>
) -> PyResult<()>
pub fn warn_explicit_bound<'py>( py: Python<'py>, category: &Bound<'py, PyAny>, message: &str, filename: &str, lineno: i32, module: Option<&str>, registry: Option<&Bound<'py, PyAny>> ) -> PyResult<()>
Issues a warning message, with more control over the warning attributes.
May return a PyErr
if warnings-as-errors is enabled.
Equivalent to warnings.warn_explicit()
in Python.
The category
should be one of the Warning
classes available in
pyo3::exceptions
, or a subclass.
sourcepub fn clone_ref(&self, py: Python<'_>) -> PyErr
pub fn clone_ref(&self, py: Python<'_>) -> PyErr
Clone the PyErr. This requires the GIL, which is why PyErr does not implement Clone.
§Examples
use pyo3::{exceptions::PyTypeError, PyErr, Python, prelude::PyAnyMethods};
Python::with_gil(|py| {
let err: PyErr = PyTypeError::new_err(("some type error",));
let err_clone = err.clone_ref(py);
assert!(err.get_type_bound(py).is(&err_clone.get_type_bound(py)));
assert!(err.value_bound(py).is(err_clone.value_bound(py)));
match err.traceback_bound(py) {
None => assert!(err_clone.traceback_bound(py).is_none()),
Some(tb) => assert!(err_clone.traceback_bound(py).unwrap().is(&tb)),
}
});
Trait Implementations§
source§impl Error for PyErr
impl Error for PyErr
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
source§impl From<&CancelledError> for PyErr
impl From<&CancelledError> for PyErr
source§fn from(err: &CancelledError) -> PyErr
fn from(err: &CancelledError) -> PyErr
source§impl From<&IncompleteReadError> for PyErr
impl From<&IncompleteReadError> for PyErr
source§fn from(err: &IncompleteReadError) -> PyErr
fn from(err: &IncompleteReadError) -> PyErr
source§impl From<&InvalidStateError> for PyErr
impl From<&InvalidStateError> for PyErr
source§fn from(err: &InvalidStateError) -> PyErr
fn from(err: &InvalidStateError) -> PyErr
source§impl From<&LimitOverrunError> for PyErr
impl From<&LimitOverrunError> for PyErr
source§fn from(err: &LimitOverrunError) -> PyErr
fn from(err: &LimitOverrunError) -> PyErr
source§impl From<&PanicException> for PyErr
impl From<&PanicException> for PyErr
source§fn from(err: &PanicException) -> PyErr
fn from(err: &PanicException) -> PyErr
source§impl From<&PyArithmeticError> for PyErr
impl From<&PyArithmeticError> for PyErr
source§fn from(err: &PyArithmeticError) -> PyErr
fn from(err: &PyArithmeticError) -> PyErr
source§impl From<&PyAssertionError> for PyErr
impl From<&PyAssertionError> for PyErr
source§fn from(err: &PyAssertionError) -> PyErr
fn from(err: &PyAssertionError) -> PyErr
source§impl From<&PyAttributeError> for PyErr
impl From<&PyAttributeError> for PyErr
source§fn from(err: &PyAttributeError) -> PyErr
fn from(err: &PyAttributeError) -> PyErr
source§impl From<&PyBaseException> for PyErr
impl From<&PyBaseException> for PyErr
source§fn from(err: &PyBaseException) -> PyErr
fn from(err: &PyBaseException) -> PyErr
source§impl From<&PyBlockingIOError> for PyErr
impl From<&PyBlockingIOError> for PyErr
source§fn from(err: &PyBlockingIOError) -> PyErr
fn from(err: &PyBlockingIOError) -> PyErr
source§impl From<&PyBrokenPipeError> for PyErr
impl From<&PyBrokenPipeError> for PyErr
source§fn from(err: &PyBrokenPipeError) -> PyErr
fn from(err: &PyBrokenPipeError) -> PyErr
source§impl From<&PyBufferError> for PyErr
impl From<&PyBufferError> for PyErr
source§fn from(err: &PyBufferError) -> PyErr
fn from(err: &PyBufferError) -> PyErr
source§impl From<&PyBytesWarning> for PyErr
impl From<&PyBytesWarning> for PyErr
source§fn from(err: &PyBytesWarning) -> PyErr
fn from(err: &PyBytesWarning) -> PyErr
source§impl From<&PyChildProcessError> for PyErr
impl From<&PyChildProcessError> for PyErr
source§fn from(err: &PyChildProcessError) -> PyErr
fn from(err: &PyChildProcessError) -> PyErr
source§impl From<&PyConnectionAbortedError> for PyErr
impl From<&PyConnectionAbortedError> for PyErr
source§fn from(err: &PyConnectionAbortedError) -> PyErr
fn from(err: &PyConnectionAbortedError) -> PyErr
source§impl From<&PyConnectionError> for PyErr
impl From<&PyConnectionError> for PyErr
source§fn from(err: &PyConnectionError) -> PyErr
fn from(err: &PyConnectionError) -> PyErr
source§impl From<&PyConnectionRefusedError> for PyErr
impl From<&PyConnectionRefusedError> for PyErr
source§fn from(err: &PyConnectionRefusedError) -> PyErr
fn from(err: &PyConnectionRefusedError) -> PyErr
source§impl From<&PyConnectionResetError> for PyErr
impl From<&PyConnectionResetError> for PyErr
source§fn from(err: &PyConnectionResetError) -> PyErr
fn from(err: &PyConnectionResetError) -> PyErr
source§impl From<&PyDeprecationWarning> for PyErr
impl From<&PyDeprecationWarning> for PyErr
source§fn from(err: &PyDeprecationWarning) -> PyErr
fn from(err: &PyDeprecationWarning) -> PyErr
source§impl From<&PyEOFError> for PyErr
impl From<&PyEOFError> for PyErr
source§fn from(err: &PyEOFError) -> PyErr
fn from(err: &PyEOFError) -> PyErr
source§impl From<&PyEncodingWarning> for PyErr
impl From<&PyEncodingWarning> for PyErr
source§fn from(err: &PyEncodingWarning) -> PyErr
fn from(err: &PyEncodingWarning) -> PyErr
source§impl From<&PyEnvironmentError> for PyErr
impl From<&PyEnvironmentError> for PyErr
source§fn from(err: &PyEnvironmentError) -> PyErr
fn from(err: &PyEnvironmentError) -> PyErr
source§impl From<&PyException> for PyErr
impl From<&PyException> for PyErr
source§fn from(err: &PyException) -> PyErr
fn from(err: &PyException) -> PyErr
source§impl From<&PyFileExistsError> for PyErr
impl From<&PyFileExistsError> for PyErr
source§fn from(err: &PyFileExistsError) -> PyErr
fn from(err: &PyFileExistsError) -> PyErr
source§impl From<&PyFileNotFoundError> for PyErr
impl From<&PyFileNotFoundError> for PyErr
source§fn from(err: &PyFileNotFoundError) -> PyErr
fn from(err: &PyFileNotFoundError) -> PyErr
source§impl From<&PyFloatingPointError> for PyErr
impl From<&PyFloatingPointError> for PyErr
source§fn from(err: &PyFloatingPointError) -> PyErr
fn from(err: &PyFloatingPointError) -> PyErr
source§impl From<&PyFutureWarning> for PyErr
impl From<&PyFutureWarning> for PyErr
source§fn from(err: &PyFutureWarning) -> PyErr
fn from(err: &PyFutureWarning) -> PyErr
source§impl From<&PyGeneratorExit> for PyErr
impl From<&PyGeneratorExit> for PyErr
source§fn from(err: &PyGeneratorExit) -> PyErr
fn from(err: &PyGeneratorExit) -> PyErr
source§impl From<&PyImportError> for PyErr
impl From<&PyImportError> for PyErr
source§fn from(err: &PyImportError) -> PyErr
fn from(err: &PyImportError) -> PyErr
source§impl From<&PyImportWarning> for PyErr
impl From<&PyImportWarning> for PyErr
source§fn from(err: &PyImportWarning) -> PyErr
fn from(err: &PyImportWarning) -> PyErr
source§impl From<&PyIndexError> for PyErr
impl From<&PyIndexError> for PyErr
source§fn from(err: &PyIndexError) -> PyErr
fn from(err: &PyIndexError) -> PyErr
source§impl From<&PyInterruptedError> for PyErr
impl From<&PyInterruptedError> for PyErr
source§fn from(err: &PyInterruptedError) -> PyErr
fn from(err: &PyInterruptedError) -> PyErr
source§impl From<&PyIsADirectoryError> for PyErr
impl From<&PyIsADirectoryError> for PyErr
source§fn from(err: &PyIsADirectoryError) -> PyErr
fn from(err: &PyIsADirectoryError) -> PyErr
source§impl From<&PyKeyError> for PyErr
impl From<&PyKeyError> for PyErr
source§fn from(err: &PyKeyError) -> PyErr
fn from(err: &PyKeyError) -> PyErr
source§impl From<&PyKeyboardInterrupt> for PyErr
impl From<&PyKeyboardInterrupt> for PyErr
source§fn from(err: &PyKeyboardInterrupt) -> PyErr
fn from(err: &PyKeyboardInterrupt) -> PyErr
source§impl From<&PyLookupError> for PyErr
impl From<&PyLookupError> for PyErr
source§fn from(err: &PyLookupError) -> PyErr
fn from(err: &PyLookupError) -> PyErr
source§impl From<&PyMemoryError> for PyErr
impl From<&PyMemoryError> for PyErr
source§fn from(err: &PyMemoryError) -> PyErr
fn from(err: &PyMemoryError) -> PyErr
source§impl From<&PyModuleNotFoundError> for PyErr
impl From<&PyModuleNotFoundError> for PyErr
source§fn from(err: &PyModuleNotFoundError) -> PyErr
fn from(err: &PyModuleNotFoundError) -> PyErr
source§impl From<&PyNameError> for PyErr
impl From<&PyNameError> for PyErr
source§fn from(err: &PyNameError) -> PyErr
fn from(err: &PyNameError) -> PyErr
source§impl From<&PyNotADirectoryError> for PyErr
impl From<&PyNotADirectoryError> for PyErr
source§fn from(err: &PyNotADirectoryError) -> PyErr
fn from(err: &PyNotADirectoryError) -> PyErr
source§impl From<&PyNotImplementedError> for PyErr
impl From<&PyNotImplementedError> for PyErr
source§fn from(err: &PyNotImplementedError) -> PyErr
fn from(err: &PyNotImplementedError) -> PyErr
source§impl From<&PyOverflowError> for PyErr
impl From<&PyOverflowError> for PyErr
source§fn from(err: &PyOverflowError) -> PyErr
fn from(err: &PyOverflowError) -> PyErr
source§impl From<&PyPendingDeprecationWarning> for PyErr
impl From<&PyPendingDeprecationWarning> for PyErr
source§fn from(err: &PyPendingDeprecationWarning) -> PyErr
fn from(err: &PyPendingDeprecationWarning) -> PyErr
source§impl From<&PyPermissionError> for PyErr
impl From<&PyPermissionError> for PyErr
source§fn from(err: &PyPermissionError) -> PyErr
fn from(err: &PyPermissionError) -> PyErr
source§impl From<&PyProcessLookupError> for PyErr
impl From<&PyProcessLookupError> for PyErr
source§fn from(err: &PyProcessLookupError) -> PyErr
fn from(err: &PyProcessLookupError) -> PyErr
source§impl From<&PyRecursionError> for PyErr
impl From<&PyRecursionError> for PyErr
source§fn from(err: &PyRecursionError) -> PyErr
fn from(err: &PyRecursionError) -> PyErr
source§impl From<&PyReferenceError> for PyErr
impl From<&PyReferenceError> for PyErr
source§fn from(err: &PyReferenceError) -> PyErr
fn from(err: &PyReferenceError) -> PyErr
source§impl From<&PyResourceWarning> for PyErr
impl From<&PyResourceWarning> for PyErr
source§fn from(err: &PyResourceWarning) -> PyErr
fn from(err: &PyResourceWarning) -> PyErr
source§impl From<&PyRuntimeError> for PyErr
impl From<&PyRuntimeError> for PyErr
source§fn from(err: &PyRuntimeError) -> PyErr
fn from(err: &PyRuntimeError) -> PyErr
source§impl From<&PyRuntimeWarning> for PyErr
impl From<&PyRuntimeWarning> for PyErr
source§fn from(err: &PyRuntimeWarning) -> PyErr
fn from(err: &PyRuntimeWarning) -> PyErr
source§impl From<&PyStopAsyncIteration> for PyErr
impl From<&PyStopAsyncIteration> for PyErr
source§fn from(err: &PyStopAsyncIteration) -> PyErr
fn from(err: &PyStopAsyncIteration) -> PyErr
source§impl From<&PyStopIteration> for PyErr
impl From<&PyStopIteration> for PyErr
source§fn from(err: &PyStopIteration) -> PyErr
fn from(err: &PyStopIteration) -> PyErr
source§impl From<&PySyntaxError> for PyErr
impl From<&PySyntaxError> for PyErr
source§fn from(err: &PySyntaxError) -> PyErr
fn from(err: &PySyntaxError) -> PyErr
source§impl From<&PySyntaxWarning> for PyErr
impl From<&PySyntaxWarning> for PyErr
source§fn from(err: &PySyntaxWarning) -> PyErr
fn from(err: &PySyntaxWarning) -> PyErr
source§impl From<&PySystemError> for PyErr
impl From<&PySystemError> for PyErr
source§fn from(err: &PySystemError) -> PyErr
fn from(err: &PySystemError) -> PyErr
source§impl From<&PySystemExit> for PyErr
impl From<&PySystemExit> for PyErr
source§fn from(err: &PySystemExit) -> PyErr
fn from(err: &PySystemExit) -> PyErr
source§impl From<&PyTimeoutError> for PyErr
impl From<&PyTimeoutError> for PyErr
source§fn from(err: &PyTimeoutError) -> PyErr
fn from(err: &PyTimeoutError) -> PyErr
source§impl From<&PyTypeError> for PyErr
impl From<&PyTypeError> for PyErr
source§fn from(err: &PyTypeError) -> PyErr
fn from(err: &PyTypeError) -> PyErr
source§impl From<&PyUnboundLocalError> for PyErr
impl From<&PyUnboundLocalError> for PyErr
source§fn from(err: &PyUnboundLocalError) -> PyErr
fn from(err: &PyUnboundLocalError) -> PyErr
source§impl From<&PyUnicodeDecodeError> for PyErr
impl From<&PyUnicodeDecodeError> for PyErr
source§fn from(err: &PyUnicodeDecodeError) -> PyErr
fn from(err: &PyUnicodeDecodeError) -> PyErr
source§impl From<&PyUnicodeEncodeError> for PyErr
impl From<&PyUnicodeEncodeError> for PyErr
source§fn from(err: &PyUnicodeEncodeError) -> PyErr
fn from(err: &PyUnicodeEncodeError) -> PyErr
source§impl From<&PyUnicodeError> for PyErr
impl From<&PyUnicodeError> for PyErr
source§fn from(err: &PyUnicodeError) -> PyErr
fn from(err: &PyUnicodeError) -> PyErr
source§impl From<&PyUnicodeTranslateError> for PyErr
impl From<&PyUnicodeTranslateError> for PyErr
source§fn from(err: &PyUnicodeTranslateError) -> PyErr
fn from(err: &PyUnicodeTranslateError) -> PyErr
source§impl From<&PyUnicodeWarning> for PyErr
impl From<&PyUnicodeWarning> for PyErr
source§fn from(err: &PyUnicodeWarning) -> PyErr
fn from(err: &PyUnicodeWarning) -> PyErr
source§impl From<&PyUserWarning> for PyErr
impl From<&PyUserWarning> for PyErr
source§fn from(err: &PyUserWarning) -> PyErr
fn from(err: &PyUserWarning) -> PyErr
source§impl From<&PyValueError> for PyErr
impl From<&PyValueError> for PyErr
source§fn from(err: &PyValueError) -> PyErr
fn from(err: &PyValueError) -> PyErr
source§impl From<&PyZeroDivisionError> for PyErr
impl From<&PyZeroDivisionError> for PyErr
source§fn from(err: &PyZeroDivisionError) -> PyErr
fn from(err: &PyZeroDivisionError) -> PyErr
source§impl From<&QueueEmpty> for PyErr
impl From<&QueueEmpty> for PyErr
source§fn from(err: &QueueEmpty) -> PyErr
fn from(err: &QueueEmpty) -> PyErr
source§impl From<&TimeoutError> for PyErr
impl From<&TimeoutError> for PyErr
source§fn from(err: &TimeoutError) -> PyErr
fn from(err: &TimeoutError) -> PyErr
source§impl From<AddrParseError> for PyErr
impl From<AddrParseError> for PyErr
source§fn from(err: AddrParseError) -> PyErr
fn from(err: AddrParseError) -> PyErr
source§impl From<DecodeUtf16Error> for PyErr
impl From<DecodeUtf16Error> for PyErr
source§fn from(err: DecodeUtf16Error) -> PyErr
fn from(err: DecodeUtf16Error) -> PyErr
source§impl From<DowncastError<'_, '_>> for PyErr
impl From<DowncastError<'_, '_>> for PyErr
Convert DowncastError
to Python TypeError
.
source§fn from(err: DowncastError<'_, '_>) -> PyErr
fn from(err: DowncastError<'_, '_>) -> PyErr
source§impl From<DowncastIntoError<'_>> for PyErr
impl From<DowncastIntoError<'_>> for PyErr
Convert DowncastIntoError
to Python TypeError
.
source§fn from(err: DowncastIntoError<'_>) -> PyErr
fn from(err: DowncastIntoError<'_>) -> PyErr
source§impl From<Error> for PyErr
impl From<Error> for PyErr
Create PyErr
from io::Error
(OSError
except if the io::Error
is wrapping a Python exception,
in this case the exception is returned)
source§impl From<FromUtf16Error> for PyErr
impl From<FromUtf16Error> for PyErr
source§fn from(err: FromUtf16Error) -> PyErr
fn from(err: FromUtf16Error) -> PyErr
source§impl From<FromUtf8Error> for PyErr
impl From<FromUtf8Error> for PyErr
source§fn from(err: FromUtf8Error) -> PyErr
fn from(err: FromUtf8Error) -> PyErr
source§impl From<Infallible> for PyErr
impl From<Infallible> for PyErr
source§fn from(_: Infallible) -> PyErr
fn from(_: Infallible) -> PyErr
source§impl<W> From<IntoInnerError<W>> for PyErr
impl<W> From<IntoInnerError<W>> for PyErr
source§fn from(err: IntoInnerError<W>) -> PyErr
fn from(err: IntoInnerError<W>) -> PyErr
source§impl From<IntoStringError> for PyErr
impl From<IntoStringError> for PyErr
source§fn from(err: IntoStringError) -> PyErr
fn from(err: IntoStringError) -> PyErr
source§impl From<ParseBoolError> for PyErr
impl From<ParseBoolError> for PyErr
source§fn from(err: ParseBoolError) -> PyErr
fn from(err: ParseBoolError) -> PyErr
source§impl From<ParseFloatError> for PyErr
impl From<ParseFloatError> for PyErr
source§fn from(err: ParseFloatError) -> PyErr
fn from(err: ParseFloatError) -> PyErr
source§impl From<ParseIntError> for PyErr
impl From<ParseIntError> for PyErr
source§fn from(err: ParseIntError) -> PyErr
fn from(err: ParseIntError) -> PyErr
source§impl From<PyBorrowError> for PyErr
impl From<PyBorrowError> for PyErr
source§fn from(other: PyBorrowError) -> Self
fn from(other: PyBorrowError) -> Self
source§impl From<PyBorrowMutError> for PyErr
impl From<PyBorrowMutError> for PyErr
source§fn from(other: PyBorrowMutError) -> Self
fn from(other: PyBorrowMutError) -> Self
source§impl<'a> From<PyDowncastError<'a>> for PyErr
impl<'a> From<PyDowncastError<'a>> for PyErr
Convert PyDowncastError
to Python TypeError
.
source§fn from(err: PyDowncastError<'_>) -> PyErr
fn from(err: PyDowncastError<'_>) -> PyErr
source§impl From<Report> for PyErr
Available on crate feature eyre
only.
impl From<Report> for PyErr
eyre
only.Converts eyre::Report
to a PyErr
containing a PyRuntimeError
.
If you want to raise a different Python exception you will have to do so manually. See
PyErr::new
for more information about that.
source§impl From<TryFromIntError> for PyErr
impl From<TryFromIntError> for PyErr
source§fn from(err: TryFromIntError) -> PyErr
fn from(err: TryFromIntError) -> PyErr
source§impl From<TryFromSliceError> for PyErr
impl From<TryFromSliceError> for PyErr
source§fn from(err: TryFromSliceError) -> PyErr
fn from(err: TryFromSliceError) -> PyErr
source§impl ToPyObject for PyErr
impl ToPyObject for PyErr
impl Send for PyErr
impl Sync for PyErr
Auto Trait Implementations§
impl !Freeze for PyErr
impl !RefUnwindSafe for PyErr
impl Unpin for PyErr
impl !UnwindSafe for PyErr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more