[−][src]Struct pyo3::PyErr
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::to_object()
to get the exception instance in all cases.
ptraceback: Option<PyObject>
The PyTraceBack
object associated with the error.
Implementations
impl PyErr
[src]
pub fn new<T, V>(value: V) -> PyErr where
T: PyTypeObject,
V: ToPyObject + 'static,
[src]
T: PyTypeObject,
V: ToPyObject + 'static,
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"));
In most cases, you can use a concrete exception's constructors instead: the example is equivalent to
return Err(exceptions::TypeError::py_err("Error message")); return exceptions::TypeError::into("Error message");
pub fn from_type<A>(exc: &PyType, args: A) -> PyErr where
A: ToPyObject + 'static,
[src]
A: ToPyObject + 'static,
Constructs 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]
T: PyTypeObject,
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(py: 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
.
If the error fetched is a PanicException
(which would have originated from a panic in a
pyo3 callback) then this function will resume the panic.
pub fn new_type<'p>(
_: Python<'p>,
name: &str,
base: Option<&PyType>,
dict: Option<PyObject>
) -> NonNull<PyTypeObject>
[src]
_: Python<'p>,
name: &str,
base: Option<&PyType>,
dict: Option<PyObject>
) -> NonNull<PyTypeObject>
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]
Prints a standard traceback to sys.stderr
.
pub fn print_and_set_sys_last_vars(self, py: Python<'_>)
[src]
Prints a standard traceback to sys.stderr
, and sets
sys.last_{type,value,traceback}
attributes to this exception's data.
pub fn matches<T>(&self, py: Python<'_>, exc: T) -> bool where
T: ToBorrowedObject,
[src]
T: ToBorrowedObject,
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.
pub fn is_instance<T>(&self, py: Python<'_>) -> bool where
T: PyTypeObject,
[src]
T: PyTypeObject,
Returns 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]
py: Python<'_>,
category: &PyAny,
message: &str,
stacklevel: i32
) -> PyResult<()>
Issues 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 Debug for PyErr
[src]
impl From<AddrParseError> for PyErr
[src]
fn from(err: AddrParseError) -> PyErr
[src]
impl From<ArithmeticError> for PyErr
[src]
fn from(_err: ArithmeticError) -> PyErr
[src]
impl From<AssertionError> for PyErr
[src]
fn from(_err: AssertionError) -> PyErr
[src]
impl From<AttributeError> for PyErr
[src]
fn from(_err: AttributeError) -> PyErr
[src]
impl From<BaseException> for PyErr
[src]
fn from(_err: BaseException) -> PyErr
[src]
impl From<BlockingIOError> for PyErr
[src]
fn from(_err: BlockingIOError) -> PyErr
[src]
impl From<BrokenPipeError> for PyErr
[src]
fn from(_err: BrokenPipeError) -> PyErr
[src]
impl From<BufferError> for PyErr
[src]
fn from(_err: BufferError) -> PyErr
[src]
impl From<CancelledError> for PyErr
[src]
fn from(_err: CancelledError) -> PyErr
[src]
impl From<ChildProcessError> for PyErr
[src]
fn from(_err: ChildProcessError) -> PyErr
[src]
impl From<ConnectionAbortedError> for PyErr
[src]
fn from(_err: ConnectionAbortedError) -> PyErr
[src]
impl From<ConnectionError> for PyErr
[src]
fn from(_err: ConnectionError) -> PyErr
[src]
impl From<ConnectionRefusedError> for PyErr
[src]
fn from(_err: ConnectionRefusedError) -> PyErr
[src]
impl From<ConnectionResetError> for PyErr
[src]
fn from(_err: ConnectionResetError) -> PyErr
[src]
impl From<DecodeUtf16Error> for PyErr
[src]
fn from(err: DecodeUtf16Error) -> PyErr
[src]
impl From<EOFError> for PyErr
[src]
impl From<EnvironmentError> for PyErr
[src]
fn from(_err: EnvironmentError) -> PyErr
[src]
impl From<Error> for PyErr
[src]
Create OSError
from io::Error
impl From<Exception> for PyErr
[src]
impl From<FileExistsError> for PyErr
[src]
fn from(_err: FileExistsError) -> PyErr
[src]
impl From<FileNotFoundError> for PyErr
[src]
fn from(_err: FileNotFoundError) -> PyErr
[src]
impl From<FloatingPointError> for PyErr
[src]
fn from(_err: FloatingPointError) -> PyErr
[src]
impl From<FromUtf16Error> for PyErr
[src]
fn from(err: FromUtf16Error) -> PyErr
[src]
impl From<FromUtf8Error> for PyErr
[src]
fn from(err: FromUtf8Error) -> PyErr
[src]
impl From<GeneratorExit> for PyErr
[src]
fn from(_err: GeneratorExit) -> PyErr
[src]
impl From<IOError> for PyErr
[src]
impl From<ImportError> for PyErr
[src]
fn from(_err: ImportError) -> PyErr
[src]
impl From<IncompleteReadError> for PyErr
[src]
fn from(_err: IncompleteReadError) -> PyErr
[src]
impl From<IndexError> for PyErr
[src]
fn from(_err: IndexError) -> PyErr
[src]
impl From<Infallible> for PyErr
[src]
fn from(_: Infallible) -> PyErr
[src]
impl From<InterruptedError> for PyErr
[src]
fn from(_err: InterruptedError) -> PyErr
[src]
impl<W: 'static + Send + Debug> From<IntoInnerError<W>> for PyErr
[src]
fn from(err: IntoInnerError<W>) -> PyErr
[src]
impl From<IntoStringError> for PyErr
[src]
fn from(err: IntoStringError) -> PyErr
[src]
impl From<InvalidStateError> for PyErr
[src]
fn from(_err: InvalidStateError) -> PyErr
[src]
impl From<IsADirectoryError> for PyErr
[src]
fn from(_err: IsADirectoryError) -> PyErr
[src]
impl From<KeyError> for PyErr
[src]
impl From<KeyboardInterrupt> for PyErr
[src]
fn from(_err: KeyboardInterrupt) -> PyErr
[src]
impl From<LimitOverrunError> for PyErr
[src]
fn from(_err: LimitOverrunError) -> PyErr
[src]
impl From<LookupError> for PyErr
[src]
fn from(_err: LookupError) -> PyErr
[src]
impl From<MemoryError> for PyErr
[src]
fn from(_err: MemoryError) -> PyErr
[src]
impl From<ModuleNotFoundError> for PyErr
[src]
fn from(_err: ModuleNotFoundError) -> PyErr
[src]
impl From<NameError> for PyErr
[src]
impl From<NotADirectoryError> for PyErr
[src]
fn from(_err: NotADirectoryError) -> PyErr
[src]
impl From<NotImplementedError> for PyErr
[src]
fn from(_err: NotImplementedError) -> PyErr
[src]
impl From<NulError> for PyErr
[src]
impl From<OSError> for PyErr
[src]
impl From<OverflowError> for PyErr
[src]
fn from(_err: OverflowError) -> PyErr
[src]
impl From<PanicException> for PyErr
[src]
fn from(_err: PanicException) -> PyErr
[src]
impl From<ParseBoolError> for PyErr
[src]
fn from(err: ParseBoolError) -> PyErr
[src]
impl From<ParseFloatError> for PyErr
[src]
fn from(err: ParseFloatError) -> PyErr
[src]
impl From<ParseIntError> for PyErr
[src]
fn from(err: ParseIntError) -> PyErr
[src]
impl From<PermissionError> for PyErr
[src]
fn from(_err: PermissionError) -> PyErr
[src]
impl From<ProcessLookupError> for PyErr
[src]
fn from(_err: ProcessLookupError) -> PyErr
[src]
impl From<PyBorrowError> for PyErr
[src]
fn from(_err: PyBorrowError) -> PyErr
[src]
impl From<PyBorrowMutError> for PyErr
[src]
fn from(_err: PyBorrowMutError) -> PyErr
[src]
impl From<PyDowncastError> for PyErr
[src]
Convert PyDowncastError
to Python TypeError
.
fn from(_err: PyDowncastError) -> PyErr
[src]
impl From<PyErr> for Error
[src]
Convert PyErr
to io::Error
impl From<QueueEmpty> for PyErr
[src]
fn from(_err: QueueEmpty) -> PyErr
[src]
impl From<QueueFull> for PyErr
[src]
impl From<RecursionError> for PyErr
[src]
fn from(_err: RecursionError) -> PyErr
[src]
impl From<ReferenceError> for PyErr
[src]
fn from(_err: ReferenceError) -> PyErr
[src]
impl From<RuntimeError> for PyErr
[src]
fn from(_err: RuntimeError) -> PyErr
[src]
impl From<StopAsyncIteration> for PyErr
[src]
fn from(_err: StopAsyncIteration) -> PyErr
[src]
impl From<StopIteration> for PyErr
[src]
fn from(_err: StopIteration) -> PyErr
[src]
impl From<SyntaxError> for PyErr
[src]
fn from(_err: SyntaxError) -> PyErr
[src]
impl From<SystemError> for PyErr
[src]
fn from(_err: SystemError) -> PyErr
[src]
impl From<SystemExit> for PyErr
[src]
fn from(_err: SystemExit) -> PyErr
[src]
impl From<TimeoutError> for PyErr
[src]
fn from(_err: TimeoutError) -> PyErr
[src]
impl From<TimeoutError> for PyErr
[src]
fn from(_err: TimeoutError) -> PyErr
[src]
impl From<TryFromIntError> for PyErr
[src]
fn from(err: TryFromIntError) -> PyErr
[src]
impl From<TryFromSliceError> for PyErr
[src]
fn from(err: TryFromSliceError) -> PyErr
[src]
impl From<TypeError> for PyErr
[src]
impl From<UnboundLocalError> for PyErr
[src]
fn from(_err: UnboundLocalError) -> PyErr
[src]
impl From<UnicodeDecodeError> for PyErr
[src]
fn from(_err: UnicodeDecodeError) -> PyErr
[src]
impl From<UnicodeEncodeError> for PyErr
[src]
fn from(_err: UnicodeEncodeError) -> PyErr
[src]
impl From<UnicodeError> for PyErr
[src]
fn from(_err: UnicodeError) -> PyErr
[src]
impl From<UnicodeTranslateError> for PyErr
[src]
fn from(_err: UnicodeTranslateError) -> PyErr
[src]
impl From<Utf8Error> for PyErr
[src]
impl From<ValueError> for PyErr
[src]
fn from(_err: ValueError) -> PyErr
[src]
impl From<ZeroDivisionError> for PyErr
[src]
fn from(_err: ZeroDivisionError) -> PyErr
[src]
impl From<gaierror> for PyErr
[src]
impl From<herror> for PyErr
[src]
impl From<timeout> for PyErr
[src]
impl FromPy<PyErr> for PyObject
[src]
impl<T> Into<Result<T, PyErr>> for PyErr
[src]
Convert PyErr
to PyResult<T>
impl<'a> IntoPy<PyObject> for &'a PyErr
[src]
impl ToPyObject for PyErr
[src]
Auto Trait Implementations
impl !RefUnwindSafe for PyErr
impl !Send for PyErr
impl !Sync for PyErr
impl Unpin for PyErr
impl !UnwindSafe for PyErr
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> FromPy<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> IntoPy<U> for T where
U: FromPy<T>,
[src]
U: FromPy<T>,
impl<T> ToBorrowedObject for T where
T: ToPyObject,
[src]
T: ToPyObject,
fn with_borrowed_ptr<F, R>(&self, py: Python<'_>, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,