Add a exception handler in test connection function