diff --git a/src/err.rs b/src/err.rs index 6c168e95..b31e945a 100644 --- a/src/err.rs +++ b/src/err.rs @@ -28,6 +28,8 @@ use std::ptr; use libc::c_char; use conversion::ToPyObject; use std::ffi::CString; +use std::error::Error; +use std::fmt; /** Defines a new exception type. @@ -394,6 +396,18 @@ impl <'p> std::convert::From> for PyErr { } } +impl Error for PyErr { + fn description(&self) -> &str { + "Error originating from the rust-cpython bindings." + } +} + +impl fmt::Display for PyErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "PyErr: ptype {:?} pvalue {:?}", self.ptype, self.pvalue) + } +} + /// Construct PyObject from the result of a Python FFI call that returns a new reference (owned pointer). /// Returns `Err(PyErr)` if the pointer is `null`. /// Unsafe because the pointer might be invalid.