mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-06 06:11:25 +00:00
Add support for nested C++11 exceptions (#3608)
* Add support for nested C++11 exceptions * Remove wrong include * Fix if directive * Fix missing skipif * Simplify code and try to work around MSVC bug * Clarify comment * Further simplify code * Remove the last extra throw statement * Qualify auto * Fix typo * Add missing return for consistency * Fix clang-tidy complaint * Fix python2 stub * Make clang-tidy happy * Fix compile error * Fix python2 function signature * Extract C++20 utility and backport * Cleanup code a bit more * Improve test case * Consolidate code and fix signature * Fix typo
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "local_bindings.h"
|
||||
|
||||
#include "pybind11_tests.h"
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
// A type that should be raised as an exception in Python
|
||||
@@ -105,7 +107,6 @@ struct PythonAlreadySetInDestructor {
|
||||
py::str s;
|
||||
};
|
||||
|
||||
|
||||
TEST_SUBMODULE(exceptions, m) {
|
||||
m.def("throw_std_exception", []() {
|
||||
throw std::runtime_error("This exception was intentionally thrown.");
|
||||
@@ -281,5 +282,12 @@ TEST_SUBMODULE(exceptions, m) {
|
||||
}
|
||||
});
|
||||
|
||||
m.def("throw_nested_exception", []() {
|
||||
try {
|
||||
throw std::runtime_error("Inner Exception");
|
||||
} catch (const std::runtime_error &) {
|
||||
std::throw_with_nested(std::runtime_error("Outer Exception"));
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user