http://www.perlmonks.org?node_id=130006


in reply to DBI error and $@

Personally when I'm doing transaction handling I use Error or other exception handling modules. The addition of a little syntatic sugar make a lot of difference. You can also define your own error classes for more complex failovers.
use Error qw(:try); # ... code passes ... try { # Execute a few queries $sth->execute( $str ); # If we're here everything is fine, let's commit. $dbh->commit; } catch Error with { my $err = shift; print "Transaction Failed: $err"; $dbh->rollback; };