I'm trying to understand how to catch errors in Class::DBI. For clarity's sake, consider that I am trying to violate a unique constraint. Thus the DB will cause a call to _croak as described in the docs:
The _croak() method is passed an error message and in some cases some extra information as described below. The default behaviour is simply to call Carp::croak($message). Applications that require custom behaviour should override the _croak() method in their application base class (or table classes for table-specific behaviour). For example: use Error; sub _croak { my ($self, $message, %info) = @_; # convert errors into exception objects # except for duplicate insert errors which we'll ignore Error->throw(-text => $message, %info) unless $message =~ /^Can't insert .* duplicate/; return; }
What I'm missing (and my question is) how do I 'catch' these DB errors in my main code where I 'tried' to do the DB insert?
The DB insert looks like this:
... various Class::DBI stuff not included... $entry = Contacts->create( \%hash );
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
In reply to Catching errors with Class::DBI by freddo411
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |