I have C++ code wrapped in a boost python module.
My C++ code does something like this:
char s[2];
s[0] = (char) 160;
s[1] = '\0';
boost::python::str bs = boost::python::str(s);
i.e. it attempts to create a boost Python string from a C string that contains an unprintable character (value 160).
When I run this code from Python script, I get this error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 11: invalid start byte
which occurs as value 0xa0 (= 160) cannot be decoded.
How can I catch this error in the C++ code?