Catch all exceptions in a rails controller

后端 未结 6 1061
春和景丽
春和景丽 2020-11-28 02:20

Is there a way to catch all uncatched exceptions in a rails controller, like this:

def delete
  schedule_id = params[:scheduleId]
  begin
    Schedules.delet         


        
6条回答
  •  时光取名叫无心
    2020-11-28 03:13

    begin
      # do something dodgy
    rescue ActiveRecord::RecordNotFound
      # handle not found error
    rescue ActiveRecord::ActiveRecordError
      # handle other ActiveRecord errors
    rescue # StandardError
      # handle most other errors
    rescue Exception
      # handle everything else
      raise
    end
    

提交回复
热议问题