# Handle all the unhandled exceptions

**URL:** <https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859>\
**Category:** Rails\
**Created:** [August 21, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859 "2006-08-21T23:18:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [August 21, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859/1 "2006-08-21T23:18:33Z")

</div>

I was just thinking, how do i go about this.  
In the latest edition of AWDR, DHH talk about something like this.But i  
guess, that part of text is still not written.  
So any clues?

–  
nothing much to talk

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [August 22, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859/2 "2006-08-22T17:54:42Z")

</div>

And where should i define this method?

I have defined this method in application.rb.But it doesn’t seem to  
catch  
all errors. Or is it that, i must run in production mode to use this  
method?

On 8/22/06, Jeremy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def rescue\_action\_in\_public(exception)  
> logger.error “Ooops: #{exception}”  
> redirect\_to home\_url  
> end
> 
> jeremy
> 
> >

–  
nothing much to talk

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [August 22, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859/3 "2006-08-22T22:17:43Z")

</div>

On 8/22/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And where should i define this method?
> 
> I have defined this method in application.rb.But it doesn’t seem to catch  
> all errors. Or is it that, i must run in production mode to use this method?

It’s a controller instance method, so defining it in  
ApplicationController  
will affect all of your controllers, as you expect.

The method is only called when local\_request? is true (dev mode), so  
switch  
to production to see the error page, or set  
config.action\_controller.consider\_all\_requests\_local = false  
in config/environments/development.rb

jeremy

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [August 22, 2006, 12:20am UTC](https://www.ruby-forum.com/t/handle-all-the-unhandled-exceptions/65859/4 "2006-08-22T00:20:40Z")

</div>

On 8/21/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I was just thinking, how do i go about this.  
> In the latest edition of AWDR, DHH talk about something like this.But i  
> guess, that part of text is still not written.  
> So any clues?

[http://api.rubyonrails.com/classes/ActionController/Rescue.html#M000069](http://api.rubyonrails.com/classes/ActionController/Rescue.html#M000069)

def rescue\_action\_in\_public(exception)  
logger.error “Ooops: #{exception}”  
redirect\_to home\_url  
end

jeremy
