use strict; use warnings; use 5.012; use Exception::Class ( 'MyException', 'CommandException' => { isa => 'MyException' }, 'TimeoutException' => { isa => 'CommandException', description => 'This exception resulted from running the metrics commands' }, 'DBException' => { isa => 'MyException', description => 'DB returned error' } ); &ThrowMyException(); sub ThrowMyException() { eval{ TimeoutException->throw(error=>"This is error due to timeout") }; my $err; if ($err = Exception::Class->caught('TimeoutException') ) { #print Dumper($err); #print "err is of type ".ref($err); die $err->description . ": " . $err->error; } elsif ( $err = Exception::Class->caught("MetricsException") ) { #print Dumper($err); die $err->error; } }