perlbaski has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Creating exception classes
by Athanasius (Archbishop) on Feb 05, 2013 at 02:35 UTC | |
by perlbaski (Sexton) on Feb 05, 2013 at 18:48 UTC | |
by Athanasius (Archbishop) on Feb 06, 2013 at 06:40 UTC | |
Re: Creating exception classes
by 7stud (Deacon) on Feb 05, 2013 at 02:42 UTC | |
by tobyink (Canon) on Feb 05, 2013 at 10:08 UTC |
Back to
Seekers of Perl Wisdom