I have 10 Ruby function calls I'd like to execute and each call could possibly throw an exception. I'd like to handle each exception the same way and continue. Is there a way to do this without wrapping each line in a begin ... rescue ... end block?
[Edit]: Use case for this is a screen scraper/automation tool that uses the Selenium web driver to fill out forms. I don't want to bother checking if options in select elements exist, just fill them out as good as possible. for this, I need to call Selenium::WebDriver::Support::Select.select_by and continue if it throws a "cannot locate option with value x" exception.
I found this answer which also does what I want:
def action
yield
rescue
....
ensure
....
end
action { call1 }
action { call2 }
action { call3 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With