From db14dd902e8141b3dea011f32f1dc08d9287b7b6 Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Thu, 29 Aug 2019 17:56:58 +0100 Subject: [PATCH] Moved normalization to error_already_set ctor --- include/pybind11/pytypes.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index df0cc70df..d8bbd66c7 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -326,6 +326,8 @@ public: /// Python error indicator will be cleared. error_already_set() : std::runtime_error("") { PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); + if (m_type) + PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); } error_already_set(const error_already_set &) = default; @@ -335,9 +337,6 @@ public: virtual const char* what() const noexcept override { if (m_lazy_what.empty()) { - if (m_type) - PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); - try { m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr()); } catch (...) {