Ignoring errors

I am getting a mysql duplicate entry error.

Can I ignore the error (let the script continue), and how would I do
that?

Or should I check if the entry exists every time, before I try to add
it?

One solution I figured out is to enclose the offending line in
begin
do_something_that_causes_an_error.here
rescue
end

I was afraid it was going to take me a while to fix this, but it was
easier than I expected.
I am really starting to like Ruby.
It works, however is seems messy.
Is there a better way to do this?

On Apr 16, 3:50 pm, cumom [email protected] wrote:

I am getting a mysql duplicate entry error.

Can I ignore the error (let the script continue), and how would I do
that?

Or should I check if the entry exists every time, before I try to add
it?

If you are using Rails properly with an auto_increment id column, this
shouldn’t happen.

And inserting a duplicate row in a DB is usually a very serious
problem. You should not ignore it.