# Within some connect_to_db() function ... 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; } # Now, any DB action I take that would ordinarily return undef # will now throw an Error::Database. As long as all my DB # activity is within a try-catch area, I'm fine. :-) # Within another section, I have: my ($dbh, $fh); try { my ($properties, $datafile) = Parameter::Validate(@ARGV, 2); $dbh = Database::Connect(File::ReadProperties($properties)); my %db_values = Retrieve_DB_Values($dbh); $fh = File::Open( $datafile, mode => 'w', ); # Do more stuff here } catch Error::Simple with { my ($err, $recover) = @_; throw Error::Unknown -text => $err->text; } catch Error with { my ($err, $recover) = @_; die $err->text . $/; } otherwise { throw Error::Unknown -text => $@; } finally { Database::Disconnect($dbh); File::Close($fh); };