# Find does not raise exception

**URL:** <https://www.ruby-forum.com/t/find-does-not-raise-exception/193844>\
**Category:** Rails\
**Created:** [August 25, 2010, 1:38pm UTC](https://www.ruby-forum.com/t/find-does-not-raise-exception/193844 "2010-08-25T13:38:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 25, 2010, 1:38pm UTC](https://www.ruby-forum.com/t/find-does-not-raise-exception/193844/1 "2010-08-25T13:38:22Z")

</div>

Hi  
I have the code

def index  
@messages = message\_thread.messages  
end

private

def message\_thread  
begin  
current\_user.message\_threads.find(params[:thread\_id])  
rescue ActiveRecord::RecordNotFound  
logger.warn “No permission or thread\_id nil”  
render :file =\> “#{RAILS\_ROOT}/public/404.html”  
end  
end

```
And even if params[:id] does not have any values I dont get any

```

exception . I can’t figureout why. Please help

Thanks

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 25, 2010, 2:07pm UTC](https://www.ruby-forum.com/t/find-does-not-raise-exception/193844/2 "2010-08-25T14:07:50Z")

</div>

2010/8/25 Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> begin  
> current\_user.message\_threads.find(params[:thread\_id])  
> rescue ActiveRecord::RecordNotFound

The problem is here:

> ```
> logger.warn "No permission or thread_id nil"
> render :file => "#{RAILS_ROOT}/public/404.html"
> 
> ```
> 
> end  
> end
> 
> And even if params[:id] does not have any values I dont get any  
> exception . I can’t figureout why. Please help

You have a rescue statement which is overriding the exception:  
current\_user.message\_threads.find(params[:thread\_id]) rescue  
ActiveRecord::RecordNotFound

remove the rescue first you will see an exception.

> Thanks

* * *

Edmond  
Software Developer | Baobab Health Trust ([http://www.baobabhealth.org/](http://www.baobabhealth.org/))  
|  
Malawi

Cell: +265 999 465 137 | +265 881 234 717

_“Many people doubt open source software and probably donâ€™t realize that  
there is an alternativeâ€¦ which is just as good…” – Kevin Scannell_

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [August 26, 2010, 5:57am UTC](https://www.ruby-forum.com/t/find-does-not-raise-exception/193844/3 "2010-08-26T05:57:44Z")

</div>

Hi Edmond  
Thanks for your reply. The problem is not that. Even it enters in  
rescue, it does not render :file =\> “#{RAILS\_ROOT}/public/404.html”. But  
it continues execution and I get problem at @messages =  
message\_thread.messages

as nil.messages

Thanks  
Tom
