mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
print traceback on failed import (#537)
This commit is contained in:
parent
14bfe622f8
commit
67a68f1394
@ -511,7 +511,6 @@ PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
|
|||||||
PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
|
PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
|
||||||
PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
|
PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
|
||||||
PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
|
PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
|
||||||
PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
|
|
||||||
PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
|
PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
|
||||||
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
|
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
|
||||||
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
|
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
|
||||||
|
@ -580,7 +580,7 @@ public:
|
|||||||
static module import(const char *name) {
|
static module import(const char *name) {
|
||||||
PyObject *obj = PyImport_ImportModule(name);
|
PyObject *obj = PyImport_ImportModule(name);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
throw import_error("Module \"" + std::string(name) + "\" not found!");
|
throw error_already_set();
|
||||||
return reinterpret_steal<module>(obj);
|
return reinterpret_steal<module>(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1495,7 +1495,7 @@ PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
file = module::import("sys").attr("stdout");
|
file = module::import("sys").attr("stdout");
|
||||||
} catch (const import_error &) {
|
} catch (const error_already_set &) {
|
||||||
/* If print() is called from code that is executed as
|
/* If print() is called from code that is executed as
|
||||||
part of garbage collection during interpreter shutdown,
|
part of garbage collection during interpreter shutdown,
|
||||||
importing 'sys' can fail. Give up rather than crashing the
|
importing 'sys' can fail. Give up rather than crashing the
|
||||||
|
Loading…
Reference in New Issue
Block a user