1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
=begin
primary-frame(main):
block: -
call-site: owner
primary-frame(owner):
block: -
call-site: Proc.new B1
primary-frame(Proc.new):
block: B1
call-site: foo B1 {}
primary-frame(foo):
block: B1
call-site: y B1 {InRescue}
primary-frame(y):
block: B1
call-site: yield B1 {}
block-frame(B1):
owner: primary-frame(owner), Inactive
retry
call-site: B1.call {}
ERROR
=end
$i = 0
def y *a
# puts 'y.begin'
# raise
#rescue # uncomment -> yield retries this try block
if $yield then
yield
else
begin
$p[]
rescue
puts "Error: #{$!}"
end
end
end
def owner
$lambda = lambda do # B1
puts 'block.begin'
if ($i == 0)
$i = 1
puts 'retrying'
begin
retry
rescue
puts "Unreachable"
end
end
puts 'block.end'
end
$proc = Proc.new do # B2
puts 'block.begin'
if ($i == 0)
$i = 1
puts 'retrying'
retry
end
puts 'block.end'
end
$p = $lambda
y puts('Y')
$p = $proc
y puts('Y')
end
def foo *a
puts 'foo.begin'
raise
rescue
y puts('Y'),&$p # retries try block ($yield) / Error: retry from proc-closure (!$yield), doesn't depend on whether the block is active or not
ensure
puts 'foo.finally'
end
puts '-' * 50,'Tests []-call to a lambda and proc from with their owner active','-' * 50
$i = 0
$yield = false
owner
puts '-' * 50,'Tests yield to a lambda (with inactive owner)','-' * 50
$i = 0
$p = $lambda
$yield = true
foo puts('F'),&$p
puts '-' * 50,'Tests yield to a proc (with inactive owner)','-' * 50
$i = 0
$p = $proc
$yield = true
foo puts('F'),&$p
puts '-' * 50,'Tests []-call to a lambda with incactive owner','-' * 50
$i = 0
$p = $lambda
$yield = false
foo puts('F'),&$p
puts '-' * 50,'Tests []-call to a proc with incactive owner','-' * 50
$i = 0
$p = $proc
$yield = false
foo puts('F'),&$p
puts '-' * 50,'Tests retry in method w/o block and outside rescue','-' * 50
def bar
retry
rescue
puts "E1: #{$!}"
end
begin
bar
rescue
puts "E2: #{$!}" # exception caught here
end
|