title: Is there a way to handle multiple early return scenarios in Ruby with catch and throw?
body: <p>I am currently using <code>begin/rescue/end</code> + exceptions to implement flow control. So, here is where I am capturing the exceptions and doing different things based on which exception is raised:</p>
  
  <pre><code>collection.each do |object|
    begin
      process_object(object)
    rescue SkippedRowError
      # handle skipped row
      next
    rescue AbortedRowError
      # handle aborted row
      next
    end
  end
  </code></pre>
  
  <p>Because each object from the collection is being processed in a method (<code>process_object</code>, which calls a bunch of other methods and results in a deeply nested call stack), I can't use <code>next</code> to stop execution and proceed to the next object in the collection. Hence my use of exceptions.</p>
  
  <p>However, I have read that exceptions should not be used for flow control and that, instead, I should use <code>catch/throw</code>. So, my question:</p>
  
  <p>Is there a way to accomplish the same thing with <code>catch/throw</code>?</p>
  
  <hr>
  
  <p><strong>My conclusion so far:</strong> As far as I can tell, <code>catch/throw</code> is really only useful if you have a single scenario where you want to return early. If you have more than one scenario where you want to return early, then it looks like you have to nest <code>catch</code> blocks inside of each other. But in that case, you really only get access to a return value; there doesn't seem to be a good way to execute code.</p>