package DB::DBException; use base qw(Error); sub new { my ($self, $msg) = @_; my @args = (); local $Error::Depth = $Error::Depth + 1; local $Error::Debug = 1; # Enables storing of stacktrace $self->SUPER::new(-text => $msg, @args); return $self; } #### use strict; use warnings; use Error qw(:try); use DB::DBException; try { throw DB::DBException("Connect exception"); print "OK\n"; } catch DB::DBException with { print "DBException"; } catch Error with { print "Error"; }; print "finished";