I am trying to create exception class hierarchy. But I think I am not declaring them correctly as I am not able to refer to the exception objects.
use Exception::Class ( 'MyException', 'Commands' => { isa => 'MyException' }, 'Timeout' => { isa => 'Commands', description => 'These exceptions are resulted from running the metrics comm +ands' }, 'DBError' => { isa => 'MyException', description => 'DB returned error' } ); ThrowMyException(); sub ThrowMyException() { eval{MyException::Commands::Timeout->throw(error=>"This is error d +ue to timeout");}; my $err; if($err=Exception::Class->caught('MyException::Commands::Timeo +ut')){ #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; } }
Can somebody see what is wrong with the code?
In reply to Creating exception classes by perlbaski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |