I am writing some Python code that uses a library to communicate with an external piece of hardware over USB. When the hardware library is unable to connect to the device, it returns False – otherwise it returns True.
I would like to examine this return and use it to trigger an exception – to be more Pythonic. What would be the most appropriate exception type to throw?
An
IOError. From the docs:You may want to wrap this in your own exception like:
and raise that instead. This gives the calling code more options on how to handle the error.