The simplest solution would be to pass your code to the method in the form of a block and go to it in the start / save expression:
def run_code_and_handle_exceptions begin yield rescue 1... rescue 2... rescue 3... rescue 4... end end
You might want to find a more concise method name than run_code_and_handle_exceptions!
source share