added convinience method
This commit is contained in:
parent
8d728663d7
commit
257be7119c
17
src/err.rs
17
src/err.rs
|
@ -19,7 +19,7 @@
|
|||
use std;
|
||||
use python::{PythonObject, ToPythonPointer, Python, PythonObjectDowncastError,
|
||||
PythonObjectWithTypeObject, PyClone, PyDrop};
|
||||
use objects::{PyObject, PyType, exc};
|
||||
use objects::{PyObject, PyType, ToPyTuple, exc};
|
||||
#[cfg(feature="python27-sys")]
|
||||
use objects::oldstyle::PyClass;
|
||||
use ffi;
|
||||
|
@ -268,6 +268,21 @@ impl 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 `py.get_type::<exc::RuntimeError>()`.
|
||||
/// `args` is the a tuple of arguments to pass to the exception constructor.
|
||||
#[inline]
|
||||
pub fn new_err<A>(py: Python, exc: &PyType, args: A) -> PyErr
|
||||
where A: ToPyTuple
|
||||
{
|
||||
let exc = exc.clone_ref(py);
|
||||
PyErr {
|
||||
ptype: exc.into_object(),
|
||||
pvalue: Some(args.to_py_tuple(py).into_object()),
|
||||
ptraceback: None
|
||||
}
|
||||
}
|
||||
|
||||
/// Print a standard traceback to sys.stderr.
|
||||
pub fn print(self, py: Python) {
|
||||
self.restore(py);
|
||||
|
|
Loading…
Reference in New Issue