---
title: "Rails记录异常"
author: "机器人"
date: "2009-11-17T16:49:26Z"
tags: []
slug: "rails"
draft: false
lastmod: "2009-11-17T16:49:26Z"
id: 519042
url: "https://bot.iteye.com/blog/519042"
---

```ruby
  def rescue_action_in_public(exception)
    case exception
    when *self.class.exceptions_to_treat_as_404
      render_404
    else
      log_exception(exception)
      render :text => "#{exception.class}"  and return
    end
  end

  def log_exception(exception)
    LoggedException.create(
      :action_name => self.action_name,
      :controller_name => self.controller_name,
      :exception_class => exception.class.to_s,
      :message => exception.clean_message,
      :request => request.parameters.inspect,
      :session => request.session.instance_variable_get("@data")
    )
  end
```