I believe this is by design. Exit throws an exception (SystemExit). The exc=
eption is not rescued by a default rescue clause because it doesn't derive =
from StandardError. Thus the raise in ensure gets called and it raises Runt=
imeError which gets caught in the outer rescue because RuntimeError <: Stan=
dardError.

Tomas

From: Shri Borde [mailto:Shri.Borde / microsoft.com]
Sent: Monday, January 12, 2009 12:32 PM
To: ironruby-core / rubyforge.org; ruby-core / ruby-lang.org
Subject: [ruby-core:21289] MRI 1.8.6 bug - exit is ignored if ensure clause=
 throws exception which is caught by outer rescue

The following code snippet does print "after foo" when using MRI 1.8.6 on W=
indows Vista, showing that exit is ignored. Any thoughts on whether this is=
 by design, a known bug, or a new issue? If it's the latter, should I open =
a bug for it?

def foo
  begin
    begin
      begin
        exit
      rescue
        puts "We never reach here"
      end
    ensure
      raise "exception from ensure"
    end
  rescue
    puts "We do reach here, which is unexpected"
  end
end

foo
print "after foo"

Thanks,
Shri