eval { $sth->execute(); ... }; if ( $@ ) { # log the full error message write_log( $sth->errstr ); # and re-throw the common message die 'HEY!!!! Something is messed up here!'; }