# Right way to handle exceptions of controller actions?

**URL:** <https://www.ruby-forum.com/t/right-way-to-handle-exceptions-of-controller-actions/107335>\
**Category:** Rails\
**Created:** [June 20, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/right-way-to-handle-exceptions-of-controller-actions/107335 "2007-06-20T17:09:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anildigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@anildigital](https://www.ruby-forum.com/u/anildigital)\
**Post date:** [June 20, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/right-way-to-handle-exceptions-of-controller-actions/107335/1 "2007-06-20T17:09:55Z")

</div>

Hi all,

I use rescue\_action\_in\_public(e) and rescue\_action\_locally(e) methods  
for  
catching the controller exceptions. I render some templates, also the  
standard error static html pages. Is there any other standard way to  
handle  
controller exceptions?

Regards,  
Anil W.  
[http://anilwadghule.com/blog](http://anilwadghule.com/blog)

---

<div class="post-metadata">

**Author:** ![anildigital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@anildigital](https://www.ruby-forum.com/u/anildigital)\
**Post date:** [June 21, 2007, 9:52am UTC](https://www.ruby-forum.com/t/right-way-to-handle-exceptions-of-controller-actions/107335/2 "2007-06-21T09:52:29Z")

</div>

I render some templates, also the

> standard error static html pages. Is there any other standard way to  
> handle  
> controller exceptions?

checkit:

def action\_in\_controller

# a couple of bad statements that raise errors; per error, it gets

sent to the

# rescue clause that catches that specific error:

foo = 5 + “string” # TypeError  
bar = ActiveRecordModel.find(23452345234523452345234) #  
RecordNotFound  
blah = “nochie” + un\_inited\_var  
…  
…  
…  
rescue TypeError  
render\_text “we added two bad datatypes”  
rescue RecordNotFound  
render\_text “we looked up a record that doesn’t exist”  
rescue  
render\_text “generic rescue”  
end

🙂

shai
