Moved normalization to error_already_set ctor

This commit is contained in:
Sergei Lebedev 2019-08-29 17:56:58 +01:00
parent 115a757a5d
commit db14dd902e

View File

@ -326,6 +326,8 @@ public:
/// Python error indicator will be cleared. /// Python error indicator will be cleared.
error_already_set() : std::runtime_error("") { error_already_set() : std::runtime_error("") {
PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); 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; error_already_set(const error_already_set &) = default;
@ -335,9 +337,6 @@ public:
virtual const char* what() const noexcept override { virtual const char* what() const noexcept override {
if (m_lazy_what.empty()) { if (m_lazy_what.empty()) {
if (m_type)
PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());
try { try {
m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr()); m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr());
} catch (...) { } catch (...) {