my $dbh = DBI->connect(... ,{RaiseError => 1}); do { local $SIG{__ERROR__} = \&my_handler; # database code }