Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instance_eval causes ensure to execute before rescue #2933

Closed
jbreeden opened this issue Sep 2, 2015 · 1 comment
Closed

instance_eval causes ensure to execute before rescue #2933

jbreeden opened this issue Sep 2, 2015 · 1 comment

Comments

@jbreeden
Copy link
Contributor

jbreeden commented Sep 2, 2015

If I raise an exception with a simple raise expression, all is well. However, if I raise from an instance_eval the ensure clause is executed before the rescue clause. This is demonstrated below.

class HellRaiser
  def raise_hell
    order = [:enter_raise_hell]
    begin
      order.push :begin
      raise 'error'
    rescue
      order.push :rescue
    ensure
      order.push :ensure
    end
    order
  end
end

hell_raiser = HellRaiser.new
hell_raiser.raise_hell
#=> [:enter_raise_hell, :begin, :rescue, :ensure]

class HellRaiser
  def raise_hell
    order = [:enter_raise_hell]
    begin
      order.push :begin
      self.instance_eval("raise 'error'")
    rescue
      order.push :rescue
    ensure
      order.push :ensure
    end
    order
  end
end

hell_raiser = HellRaiser.new
hell_raiser.raise_hell
#=> [:enter_raise_hell, :begin, :ensure, :rescue]
@0x1eef
Copy link
Contributor

0x1eef commented Sep 7, 2015

@jbreeden I like your choice of class & method name :)

yasuyuki added a commit to yasuyuki/mruby that referenced this issue Oct 4, 2015
yasuyuki added a commit to yasuyuki/mruby that referenced this issue Oct 4, 2015
matz added a commit that referenced this issue Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants