try:
    with closing(getConnection(database)) as connection:
        with closing(connection.cursor()) as cursor:
            cursor.execute('some query')
except:
    pass
Using a variable in a try,catch,finally statement without declaring it outside