13
13
#include " buffer_info.h"
14
14
15
15
#include < exception>
16
- #include < stdexcept>
17
16
#include < string>
18
17
#include < type_traits>
19
18
#include < utility>
@@ -388,16 +387,13 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
388
387
}
389
388
}
390
389
391
- error_already_set (const error_already_set &) noexcept = default ;
392
- error_already_set (error_already_set &&) noexcept = default ;
390
+ error_already_set (const error_already_set &) = default ;
391
+ error_already_set (error_already_set &&) = default ;
393
392
394
393
inline ~error_already_set () override ;
395
394
396
395
const char *what () const noexcept override {
397
- auto *sup_what = std::runtime_error::what ();
398
- if (sup_what[0 ] != ' \0 ' ) {
399
- return sup_what;
400
- } else if (m_lazy_what.empty ()) {
396
+ if (m_lazy_what.empty ()) {
401
397
try {
402
398
m_lazy_what = detail::error_string (m_type.ptr (), m_value.ptr (), m_trace.ptr ());
403
399
} catch (const std::exception &e) {
@@ -411,7 +407,6 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
411
407
return m_lazy_what.c_str ();
412
408
}
413
409
}
414
-
415
410
assert (!m_lazy_what.empty ());
416
411
return m_lazy_what.c_str ();
417
412
}
@@ -420,8 +415,7 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
420
415
// / already set it is cleared first. After this call, the current object no longer stores the
421
416
// / error variables (but the `.what()` string is still available).
422
417
void restore () {
423
- // Abuse assignment operator to cache what()
424
- std::runtime_error::operator =(std::runtime_error (what ())); // Force-build `.what()`.
418
+ what (); // Force-build `.what()`.
425
419
if (m_lazy_what.empty ()) {
426
420
pybind11_fail (" Critical error building lazy error_string()." );
427
421
}
0 commit comments