【发布时间】:2014-02-27 19:01:09
【问题描述】:
如何在 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。
【问题讨论】: