How to safely convert std::runtime_error that contains non UTF8 words to Python RuntimeError after pybind v2.7 #5900
TianciXiao
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I implement a pybind method, which will call another lib to do some things. But this lib may raise exceptions contains non UTF8 words like '0xff'. So when I catch that exception and try to raise my own std::runtime_error. This pybind method will raise 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position xxx: invalid start byte' when I call MyFunc from Python.
This situation only occurs with pybind after v2.7. I guess it may be relative to the change about py::str https://pybind11.readthedocs.io/en/stable/upgrade.html#v2-7
So is there a safe way to convert std::runtime_error that contains non UTF8 words to Python RuntimeError?
Beta Was this translation helpful? Give feedback.
All reactions