Rails (转) Rails 中如何处理异常!

zouyu · June 25, 2018 · Last by gakki replied at June 27, 2018 · 2191 hits
  1. Exception 和 StandardError 的区别
    https://blog.rebased.pl/2016/11/07/api-error-handling.html

  2. 建议在 rails 中全局捕获异常,这个样的话,不会出现在 action 中一坨一坨 begin rescue 的代码

  3. 应该捕获的是你应用产生的异常。PS,个人认为绝大部分异常来自于数据输入和网络请求

  4. 想要全局捕获异常,在 action 中就要主动抛出或者调用能抛出异常的方法 例如用 save! 取代 save
    https://blog.rebased.pl/2016/11/07/api-error-handling.html
    https://medium.com/rails-ember-beyond/error-handling-in-rails-the-modular-way-9afcddd2fe1b

这就是我这几天想要的。谢谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.