Handling UnicodeErrors #11605
-
I am getting unicode errors on a LoRa link and can't trap these errors. I am aware that there is not a specific UnicodeError in Micropython, but thought OSError caught all exceptions. This doesn't seem to work: try:
PV_msg = msg.decode('utf-8')
print(f'the message is {PV_msg}')
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write('bad message after decode: ' + str(error) + '\n')
except OSError:
pass |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This is not the case. It catches exceptions that come from OS-level functionality (e.g. filesystem, process, etc). The line If you want to catch all normal exceptions, then you want Although in this case I suspect you want to use See But also you might find it easier to see the hierarchy here: https://github.com/micropython/micropython/blob/master/py/objexcept.c#L304 |
Beta Was this translation helpful? Give feedback.
-
As a follow-up of sorts to the previous thread, I do not recommend this as a way of detecting transmission errors as you can still get corrupted/malformed messages that will pass this check. You should have some sort of proper message integrity check, e.g. a checksum. |
Beta Was this translation helpful? Give feedback.
As a follow-up of sorts to the previous thread, I do not recommend this as a way of detecting transmission errors as you can still get corrupted/malformed messages that will pass this check. You should have some sort of proper message integrity check, e.g. a checksum.