Skip to content

Trying to catch exception from python in c++ hangs #4673

Answered by jagerman
tvercaut asked this question in Q&A
Discussion options

You must be logged in to vote

Am I missing something obvious to be able to catch pybind11 exceptions stemming from python?

The problem here is that your interpreter is scoped to the try { ... } and so isn't available anymore once you get to the catch, but the catch is trying to reach into python by the what() call and so the interpreter still needs to be available to do anything with the py::error_already_set exception.

If you move the py::scoped_interpreter guard{}; above the try then the code should work as expected.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tvercaut
Comment options

Answer selected by tvercaut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants