r/ruby•
dunnowins

I need to prevent my program from exiting if an exception occurs inside a particular method.

Would it make sense to do something like this:

loop do
  begin
    poller.poll
  rescue StandardError => e
    # log something somewhere
    next
  end
end

The poll process is a long poller. If an exception occurs it will crash and the program exits, however, I'd like to program to continue. The poller should not stop but for a moment if necessary. Does it make sense to basically swallow the error and restart the poll process? Is there a better way to handle this?

Thanks.

Posted Feb 21, 2016, 8:53 PM UTC

22
Loading comments…