【问题标题】:rescue that calls a method with a rescue使用救援调用方法的救援
【发布时间】:2014-08-20 23:51:23
【问题描述】:

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

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

begin
  mimiti
rescue
  puts 'rescue 2'
end

【问题讨论】:

    标签: ruby error-handling rescue


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      相关资源
      最近更新 更多