Forum: Ruby on Rails handling specific database exceptions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1a161d16b292cbacee7b4563bd0c72e8?d=identicon&s=25 Alon (Guest)
on 2006-05-30 15:45
Hi,

When an exception comes from rails, it has a name, i.e:
"AssociationTypeMismatch", so I can catch it like this:

    rescue ActiveRecord::AssociationTypeMismatch => e
    ...
    ...

However, how can I catch and handle specific exceptions that come from
the database. "rescue Exception => e" is not good enough. I want to be
able to deal with them individually. for example, mysql throws a
duplicate entry key error, how do I catch that in rails?

Thanks,
Alon.
1a161d16b292cbacee7b4563bd0c72e8?d=identicon&s=25 Alon (Guest)
on 2006-05-30 19:57
I am trying to figure out if I need to use the database specific error
codes, but I can't figure out how to access it from rails...
This topic is locked and can not be replied to.