An error code different from 0 may not necessarily means that device is not connected as a different code can be returned.
Maybe it is needed to check specifically for the two codes - "success" and "not connected" and throw for others? What do you think?