# How do I catch an ActionController Error?

**URL:** <https://www.ruby-forum.com/t/how-do-i-catch-an-actioncontroller-error/99494>\
**Category:** Rails\
**Created:** [December 13, 2005, 12:24am UTC](https://www.ruby-forum.com/t/how-do-i-catch-an-actioncontroller-error/99494 "2005-12-13T00:24:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 13, 2005, 12:24am UTC](https://www.ruby-forum.com/t/how-do-i-catch-an-actioncontroller-error/99494/1 "2005-12-13T00:24:43Z")

</div>

I can’t figure out how to have an ActionController catch it’s own  
exceptions.

For instance:

def thankyou  
begin  
render ‘nonexistentjustwanttoseetheexceptionthrownthankyou’  
rescue ActionController::ActionControllerError =\> exc  
render :text =\> exc.to\_yaml  
rescue Exception =\> exc  
render :text =\> exc.to\_yaml  
end  
end

get’s name errors - it seems that ActionController’s own exceptions  
aren’t defined within its class!!! How do I solve this?

PS Also, how do I html escape text that I want to render using render  
:text ?

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 13, 2005, 12:53am UTC](https://www.ruby-forum.com/t/how-do-i-catch-an-actioncontroller-error/99494/2 "2005-12-13T00:53:29Z")

</div>

This same question was asked yesterday, search archives. The basic idea  
is to  
use rescue\_action method.

Kent.

---

<div class="post-metadata">

**Author:** ![lstrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@lstrecv](https://www.ruby-forum.com/u/lstrecv)\
**Post date:** [December 13, 2005, 1:06am UTC](https://www.ruby-forum.com/t/how-do-i-catch-an-actioncontroller-error/99494/3 "2005-12-13T01:06:24Z")

</div>

Kent S. wrote:

> This same question was asked yesterday, search archives. The basic idea  
> is to  
> use rescue\_action method.
> 
> Kent.

Got it. Thanks.

However, the solution there won’t work for me, as I’d like to catch them  
within the actual actions, as opposed to in a general method per  
controller.

Could you explain to me why those constants (ie, the AC exception  
classes) aren’t defined - shouldn’t they have been defined when  
action\_controller.rb was included? - and how I can define them?

I’m assuming that, if I were to define them, I could then catch them  
within my action methods. Is this true?
