【发布时间】:2013-11-06 16:19:49
【问题描述】:
以下是一些 sudo 代码:
exceptions.rb
module Exceptions
class CriticalError < StandardError
# Question: How do I attach a callback to this error? Whenever this error is raised, I also want it to ping_me() as a after callback
def ping_me()
...
end
end
end
期望的结果:
raise Exceptions::CriticalError # after a callback to this error being raised, it will run the ping_me() method
问题:
如何在 Rails 中执行此操作?我看到了一个rescue_from 方法,但我认为它只能在控制器内部使用
非常感谢!
【问题讨论】:
-
不清楚你在问什么。您是在问如何拯救和重新抛出异常?你问如何使用
pagerdutyping 你?还是别的什么? -
我在问如何使用自定义错误执行此操作。例如,现在的代码会引发错误,仅此而已。如何使它自动挽救错误
标签: ruby-on-rails custom-errors custom-error-handling