Add more exception handling to connection