Skip to content

Commit ee1d13a

Browse files
committed
refine
1 parent 0987a87 commit ee1d13a

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

tests/pybind11_cross_module_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) {
3434
py::register_exception_translator([](std::exception_ptr p) {
3535
try {
3636
if (p) std::rethrow_exception(p);
37-
} catch (const tmp_e &e) {
37+
} catch (const shared_exception &e) {
3838
PyErr_SetString(PyExc_KeyError, e.what());
3939
}
4040
});

tests/test_exceptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,5 @@ TEST_SUBMODULE(exceptions, m) {
229229
// Test repr that cannot be displayed
230230
m.def("simple_bool_passthrough", [](bool x) {return x;});
231231

232-
m.def("throw_", []() { throw tmp_e(); });
232+
m.def("throw_should_be_translated_to_key_error", []() { throw shared_exception(); });
233233
}

tests/test_exceptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
// shared exceptions for cross_module_tests
66

7-
class PYBIND11_EXPORT tmp_e : public pybind11::builtin_exception {
7+
class PYBIND11_EXPORT shared_exception : public pybind11::builtin_exception {
88
public:
99
using builtin_exception::builtin_exception;
10-
explicit tmp_e() : tmp_e("") {}
10+
explicit shared_exception() : shared_exception("") {}
1111
void set_error() const override { PyErr_SetString(PyExc_RuntimeError, what()); }
1212
};

tests/test_exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_cross_module_exceptions():
4444
cm.throw_stop_iteration()
4545

4646
with pytest.raises(KeyError) as excinfo:
47-
m.throw_()
47+
# translator registered in cross_module_tests
48+
m.throw_should_be_translated_to_key_error()
4849

4950

5051
def test_python_call_in_catch():

0 commit comments

Comments
 (0)