Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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_errors ($) { my $sth = shift; return if (!$sth->err); warn $sth->errstr; if ( $debug ) { print "SQL for statement was: \"", $sth->{Statement}, "\"\n"; ... } } my $sth = $dbh->prepare(execute( $value_for_d ); check_dbi_errors( $sth ); ...
    • Hmm, I didn't look and see that the pre tag isn't allowed. bummer.

      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