my $dbh = try { DBI->connect( $conn_string, $props{USER}, $props{PWD}, { PrintError => 0, RaiseError => 1, }, ) } otherwise { throw Error::Database -text => ( $DBI::errstr || $@ || "Unknown Error: '$conn_string'" ); }; $dbh->{HandleError} = sub { throw Error::Database -text => $DBI::errstr }; return $dbh; #### package Error::Database; ################################################################################ use 5.6.0; use strict; use warnings; ################################################################################ # This is a baseclass I use for extending the standard Error class in ways that don't matter here. use Error::Base; our @ISA = qw(Error::Base); ################################################################################ sub new { my $class = shift; my $self = $class->SUPER::new(@_) || return undef; my $txt = $self->text; if ($txt =~ /text=([^=]+)./) { $self->{-text} = $1; } elsif ($txt =~ /Message String: (.*?)$/) { $self->{-text} = $1; } return $self; } 1;