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: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Ouch. Thanks.
I was reading your issue because I ran into the same issue. Lets see if I
get lucky in this one too.
…On Fri, Nov 28, 2025, 02:34 Tianci Xiao ***@***.***> wrote:
I guess you replied to the wrong person. But congratulations!
—
Reply to this email directly, view it on GitHub
<#5900 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFEHGLM462GKVOZZD4SOQT366RB7AVCNFSM6AAAAACMRGYVE2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKMJQGEZDONQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
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