heusserm (email not shown publicly)
http://www.xndev.com/AOL IM: MatthewHeusser (
Add Buddy, Send Message)
Matt Heusser is JAPH and an
XP-Er [xprogramming.com]. (The Methodology, not the Operating System.) Right now, he's doing a lot of Test Driven Development in Perl.
why not just set RaiseError? (Score:2, Informative)
on which RaiseError, was set, just wrap in
an eval:
sub GetValues {
my $a;
eval {
my $dbh = get_connection('databasename');
my $sth = $dbh->prepare('Select * from table_name');
$sth->execute();
my $r;
-derby
bail out on error (Score:3, Interesting)
Reply to This
My style -- is this wrong? (Score:2, Interesting)
if (!$dbh) {
$ok = 0;
$msg = "Failed to get connection to databasename in GetValues";
} else {
$sth = $dbh->prepare('Se
ick (Score:3, Interesting)
I find code like this pretty cringe-worthy. If you set RaiseError and HandleError, you can have something this simple:
Isn't that much nicer than 25 lines of code? I'm also not keen on returning flags for errors, you'll just have to write lots of code to check, just die if something bad happened and trap it with eval.
Reply to This
Re:ick (Score:2)
{ RaiseError = 1 } (Score:1)
Re:{ RaiseError = 1 } (Score:1)
The best way I've found is to use RaiseError => 1, which tells DBI to always throw an exception when there is an error. This way, you never have errors go unnoticed. If you want an error to not be fatal, use eval.
eval {
$dbh->do("DROP TABLE users");
};
if ( $@ ) { my_error_handler( $@ ) }
Another method I use is a function that does a little more digging for me before printing it's error message.
sub check_dbi_erro