refactor _connect exception handling