add exception handling for connection failure