Skip to content

Commit dd67a9b

Browse files
committed
Use 'raise from' in initialization
1 parent 2733c4a commit dd67a9b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/pybind11/detail/common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ extern "C" {
272272
} \
273273
}
274274

275+
#if PY_VERSION_HEX >= 0x03030000
276+
277+
#define PYBIND11_CATCH_INIT_EXCEPTIONS \
278+
catch (pybind11::error_already_set &e) { \
279+
pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \
280+
return nullptr; \
281+
} catch (const std::exception &e) { \
282+
PyErr_SetString(PyExc_ImportError, e.what()); \
283+
return nullptr; \
284+
} \
285+
286+
#else
287+
275288
#define PYBIND11_CATCH_INIT_EXCEPTIONS \
276289
catch (pybind11::error_already_set &e) { \
277290
PyErr_SetString(PyExc_ImportError, e.what()); \
@@ -281,6 +294,8 @@ extern "C" {
281294
return nullptr; \
282295
} \
283296

297+
#endif
298+
284299
/** \rst
285300
***Deprecated in favor of PYBIND11_MODULE***
286301

0 commit comments

Comments
 (0)