my $tmp_query="insert into values('','');"; eval { $sth = $dbh->prepare($tmp_query); $sth->execute(); $sth->finish(); }; if ($@) { # error... }