Added exception handling in case connect throws error