Exception Handling Approach - This is what I'm doing...

Hi - Any feedback from people re how they handle exception handling in RoR? Here’s what I’m doing…

I’ve ended up doing the following so far, some of which are adjustments to Jamis Buck’some “Exception Notification” plugin. I’m still optimizing this for my own usage as I go. Hope this helps (any ideas/feedback welcome):

Usage: if error_situation_occurs raise Error.new( “Message to User Here - Will be shown on error page”, “Additional message that will go to log file for developers”, Logger::ERROR) end

Features:

  • Separate user & developer messages

  • Do not have to catch such errors back in controller or views as the below-mentioned rails rescue frame work will handle ( i.e. less work, cleaner code)

  • Just need to raise the Error exception which then triggers/implies/carries out: (a) appropriate email message to user (b) developer specific additional message to logs

    (c) severity of log entry raised (b) triggers Email/SMS alert based on severity of the error (use of Ruby Logger severity levels)

class SomethingsController < ApplicationController def create @something = Something.create!(params[:something]) flash[:success] = “Something was created!” rescue ActiveRecord::RecordNotSaved, ActiveRecord::RecordInvalid

flash[:errors] = “Something could not be created.” render :action => “new” end end

You did say any feedback.

This is currently what we’re doing and hopefully later on when other exceptions are raised we will be notified by email.