#! perl use strict; use warnings; use Exception::Class ( 'MyException', Commands => { isa => 'MyException', }, Timeout => { isa => 'Commands', description => 'This exception results from running the metrics commands', }, DBError => { isa => 'MyException', description => 'DB returned error', }, ); ThrowMyException(); print "No error caught\n"; sub ThrowMyException # NO prototype { eval { Timeout->throw # NOT MyException::Commands::Timeout-> ( error => "This error is due to a timeout" ); }; my $err; if ($err = Exception::Class->caught('Timeout')) { die $err->description . # NOT $err->{"description"} ': ' . $err->error; # NOT $err->{"error"} } elsif ($err = Exception::Class->caught('MetricsException')) { die $err->error; } else { $err = Exception::Class->caught(); ref $err ? $err->rethrow : die $err; } }