DBI->connect_cached( $dsn, $username, $auth, {
PrintError => 1,
RaiseError => 1,
AutoInactiveDestroy => 1})or die "Could not connect to: " $DBI::errstr ."\n";
####
my $checkExist = $dbh->prepare("INSERT IGNORE INTO your statement here");
if (!$checkExist->execute()) {
die "Error: ". $checkExist->errstr ."\n";
}
####
use Try::Tiny;
try {
...
$sth->execute();
...
} catch {
# $sth->err and $DBI::err will be true if error was from DBI
warn $_; # print the error (which Try::Tiny puts into $_)
... # do whatever you need to deal with the error
};