I have a database query that I am running inside an eval, to trap the error. Problem is that the error message is outputting to console, even though it is being trapped. How do I stop the error message from doing this, as I want to parse it myself and spit back my own messages?
my $dbh = DBI->connect('dbi:Pg:dbname=database;host=localhost',
'user', 'pass',
{RaiseError => 1}
);
eval{
$sth = $dbh->prepare($sql);
$sth->execute;
};
if($@){
#Do my parse/print stuff here I know
}
You can specify ‘PrintError => 0′ in your
connectcall (or use HandleError):Or to set per statement handle:
Also, don’t depend on $@ for indicating an error. A better way to use eval is: