Fixed handling of exceptions, such as socket.timeout. Exceptions do not always have errno or msg, so we need to handle all possible cases.