Hi everyone,
In a current project I ended up writing the code below (relevant part is
the last rescue statement):
def perform_single_request(conn = init_connection)
self.last_status = 'started'
begin
response = http_call_with_retries(conn)
if validate_response(response)
handle_response_success(response, self)
else
handle_response_error(response)
end
# Error types that we're allowed to **believe** they're transient. We
want
# to save current request state, so that the next time it runs,
# it will continue from where it was.
rescue Faraday::Error::ClientError, SyncEngine::Error::RateLimitExceeded
=> e
errback(e)
save!
rescue SyncEngine::Error::Base => e
errback(e)
clear_pagination
save!* rescue Exception => e # We don't want another exception to be raised.
Here we will # *try* to finish the execution as clean as possible, but
in any case # what we want is the original exception to be re-raised,
not a different # one. begin errback(e) clear_pagination
save! rescue Exception end raise e end*
end
Do you think this is a legit use of rescue Exception? I'm a aware of some
of the issues with it, but now I'm wondering if there may be cases that
could make such code critical or dangerous.
What would be legit uses of rescue Exception?
Thanks
Sam B.