如何在 Ruby 中将恢复写入循环?这是一个示例代码。
#!/usr/bin/ruby
#
a = [1,2,3,4,5]
begin
a.each{|i|
puts i
if( i==4 ) then raise StandardError end # Dummy exception case
}
rescue =>e
# Do error handling here
next # Resume into the next item in 'begin' clause
end
但是,运行时,Ruby 会返回错误消息
test1.rb:13: Invalid next
test1.rb: compile error (SyntaxError)
我正在使用 Ruby 1.9.3。