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:
Aaron Gokaslan
2022-01-14 14:22:47 -05:00
committed by GitHub
parent f8d4aa47b6
commit d2ec836712
4 changed files with 131 additions and 13 deletions

View File

@@ -239,6 +239,14 @@ def test_nested_throws(capture):
assert str(excinfo.value) == "this is a helper-defined translated exception"
@pytest.mark.skipif("env.PY2")
def test_throw_nested_exception():
with pytest.raises(RuntimeError) as excinfo:
m.throw_nested_exception()
assert str(excinfo.value) == "Outer Exception"
assert str(excinfo.value.__cause__) == "Inner Exception"
# This can often happen if you wrap a pybind11 class in a Python wrapper
def test_invalid_repr():
class MyRepr(object):