ruby - 抢救,调用抢救方法

标签 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

最佳答案

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

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

关于ruby - 抢救,调用抢救方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25416260/

相关文章:

php - PHP自定义错误处理程序: How to determine if exception was generated within try{}catch{} block?

Ruby/Rails 跳出循环内的方法

regex - 将捕获组命名为不同的名称

c++ - 使用列表列出不可迭代的插入迭代

ruby-on-rails - 如何从按 ID 的特定顺序排序的记录数组中获取 ActiveRecord::Relation?

javascript - 如何抑制浏览器中的 javascript 错误?

ruby - 以 DRY 方式将多个错误类传递给 ruby​​ 的救援子句

ruby - 从开始救援错误返回一个变量

ruby-on-rails - Rails,按 created_at day 分组的用户数 - PostgreSQL

ruby - 在 Ruby 中,如何根据最小权重进行加权随机选择?