printing and raising exception when connection cannot be established