try/except and close connection