0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

例外のまとめ 自分用

Last updated at Posted at 2020-05-22

記事まとめ

例外の基本


パターン1
def some_method
  
  1 / 0
rescue ZeroDivisionError => e
  puts e.class
  puts e.message
  puts e.backtrace
end


パターン2
def some_method
  begin
    1 /0
  rescue ZeroDivisionError => e
    puts e.class
    puts e.message
    puts e.backtrace
  end
end

使っていい場合

仲間を道ずれにしたくない場合など

users.each do |user|
 beginn
  send_mail_to(user)
 rescue => e
   puts e.backtrace
 end
end

例外をかくポイント

  • ログを残す

    • backtraceを
  • 通知する

    • slackなどに
  • 例外の対象範囲は狭くする

  • 例外もテストする

例外の対応方針

  • 業務エラーとシステムエラーに切り分ける

    • 業務エラー
      • ユーザーミス
      • 権限エラー
    • システムエラー
      • バグ(シンタックなど)
      • ネットワーク、DBエラー
  • 業務エラー
    =>がモデルで対応
    => 返り血を検証する(saveなども true falseが返ってきている)

  • システムエラー

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?