Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access the binding at the moment of an exception in Ruby

Tags:

exception

ruby

Say I have:

begin
  2.times do
    a = 1
    1/0
  end

rescue
  puts $!
  debugger
end       

In this example, I want to get the value of a. If a is initialised in the begin block then I can access it when I rescue. However, in this example, a is block-local. Is there a way to get the binding at the moment of the exception, when I rescue?

like image 614
Vassilis Avatar asked Oct 04 '11 11:10

Vassilis


1 Answers

Can't you just put another begin,rescue block inside of the do block?

like image 156
lottscarson Avatar answered Oct 19 '22 02:10

lottscarson