print traceback on failed import (#537)
diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 7da4215..74dcbd9 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h
@@ -511,7 +511,6 @@ PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError) PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError) PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError) -PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError) 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(reference_cast_error, PyExc_RuntimeError) /// Used internally
diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 37d6139..c88273d 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h
@@ -580,7 +580,7 @@ static module import(const char *name) { PyObject *obj = PyImport_ImportModule(name); if (!obj) - throw import_error("Module \"" + std::string(name) + "\" not found!"); + throw error_already_set(); return reinterpret_steal<module>(obj); } @@ -1495,7 +1495,7 @@ } else { try { 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 part of garbage collection during interpreter shutdown, importing 'sys' can fail. Give up rather than crashing the