救援,称救援方法

时间:2014-08-20 23:51:23

标签: ruby error-handling rescue

这只打印rescue 1,有没有办法打印rescue 1rescue 2

def mimiti
  raise 'hi there!'
rescue
  puts 'rescue 1'
end

begin
  mimiti
rescue
  puts 'rescue 2'
end

1 个答案:

答案 0 :(得分:2)

是的,您可以在捕获并处理它之后重新引发异常:

def mimiti
  raise 'hi there!'
rescue StandardError => e
  puts 'rescue 1'
  raise e
end