Close when exception is thrown