I have this code that can trigger in production the "Non local exit detected!" branch. I can't understand how that can happen, since even a return will trigger a NonLocalExit exception. Even a throw will trigger an exception.
Is there any way to have exception_raised and yield_returned both false?
def transaction
  yield_returned = exception_raised = nil
  begin
    if block_given?
      result = yield
      yield_returned = true
      puts 'yield returned!'
      result
    end
    rescue Exception => exc
      exception_raised = exc
    ensure
      if block_given?
        unless yield_returned or exception_raised
          puts 'Non local exit detected!'
        end
      end
  end
end
transaction do
  puts 'good block!'
end
transaction do 
  puts 'starting transaction with block with return'
  return 
  puts 'this will not show'
end
Output:
good block!
yield returned!
starting transaction with block with return
I want to somehow output 'Non local exit detected!'. I know this happens in production, but I can't make it happen in development. Tried it with a return and with a throw, but they both raise an exception. Any other way?
 
     
     
    