Commit 67a68f13 by esquires Committed by Wenzel Jakob

print traceback on failed import (#537)

parent 14bfe622
...@@ -511,7 +511,6 @@ PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration) ...@@ -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: ...@@ -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) { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment