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

**URL:** <https://discuss.rubyonrails.org/t/exception-handling-approach-this-is-what-im-doing/23760>\
**Category:** rubyonrails-talk\
**Created:** [January 24, 2008, 6:11am UTC](https://discuss.rubyonrails.org/t/exception-handling-approach-this-is-what-im-doing/23760 "2008-01-24T06:11:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_H](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Greg\_H](https://discuss.rubyonrails.org/u/Greg_H)\
**Post date:** [January 24, 2008, 6:11am UTC](https://discuss.rubyonrails.org/t/exception-handling-approach-this-is-what-im-doing/23760/1 "2008-01-24T06:11:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [January 24, 2008, 6:19am UTC](https://discuss.rubyonrails.org/t/exception-handling-approach-this-is-what-im-doing/23760/2 "2008-01-24T06:19:52Z")

</div>

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.
