# How to read ActiveRecord errors

**URL:** <https://www.ruby-forum.com/t/how-to-read-activerecord-errors/94052>\
**Category:** Rails\
**Created:** [April 19, 2006, 8:49am UTC](https://www.ruby-forum.com/t/how-to-read-activerecord-errors/94052 "2006-04-19T08:49:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![f\_church](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@f\_church](https://www.ruby-forum.com/u/f_church)\
**Post date:** [April 19, 2006, 8:49am UTC](https://www.ruby-forum.com/t/how-to-read-activerecord-errors/94052/1 "2006-04-19T08:49:46Z")

</div>

How can ActiveRecord errors be read within the model itself?

I am deliberately putting error records in the form, however after the  
save  
command, the error messages show up in the browser.

How can the ActiveRecord messages be retrieved in the code itself,  
either in the  
model or the controller code, something like a try, except, catch ?

---

<div class="post-metadata">

**Author:** ![f\_church](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@f\_church](https://www.ruby-forum.com/u/f_church)\
**Post date:** [April 19, 2006, 9:23am UTC](https://www.ruby-forum.com/t/how-to-read-activerecord-errors/94052/2 "2006-04-19T09:23:31Z")

</div>

Hi !

2006/4/19, f church [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How can ActiveRecord errors be read within the model itself?
> 
> I am deliberately putting error records in the form, however after the save  
> command, the error messages show up in the browser.
> 
> How can the ActiveRecord messages be retrieved in the code itself, either in the  
> model or the controller code, something like a try, except, catch ?

Not sure exactly what you are after. There’s begin/rescue/ensure to  
catch exceptions, but this doesn’t catch model validation errors.

If you want to access validation errors, look at the #errors method  
and the Errors class on the Rails API: [http://api.rubyonrails.com/](http://api.rubyonrails.com/)

Hope that helps !
