# Catch MYSQL errors

**URL:** <https://www.ruby-forum.com/t/catch-mysql-errors/82579>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/catch-mysql-errors/82579 "2007-01-19T16:31:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serdar\_KSSSSlSSSSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@Serdar\_KSSSSlSSSSSS](https://www.ruby-forum.com/u/Serdar_KSSSSlSSSSSS)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/catch-mysql-errors/82579/1 "2007-01-19T16:31:30Z")

</div>

Hello,  
How does one go about catching db errors, such as:

Mysql::Error in BlogController#index  
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

## I’d rather render the error in my own layout (I do have one named application)

Cheers,  
Serdar Kilic

> **[kilic.net](http://weblog.kilic.net/)**
>
> kilic.net - the weblog of Serdar Kilic

---

<div class="post-metadata">

**Author:** ![Serdar\_KSSSSlSSSSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@Serdar\_KSSSSlSSSSSS](https://www.ruby-forum.com/u/Serdar_KSSSSlSSSSSS)\
**Post date:** [September 25, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/catch-mysql-errors/82579/2 "2007-09-25T22:48:51Z")

</div>

> Hello,  
> How does one go about catching db errors, such as:
> 
> Mysql::Error in BlogController#index  
> Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
> 
> I’d rather render the error in my own layout (I do have one named  
> application)

Look at the specific exception that is being thrown and then deal with  
it  
in a begin/rescue/end block…

-philip
