in reply to switch question

Maybe your exception classes should implement errorcode()?

Cheers Christoph
BEGIN{ sub Exception::Class::Base::errorcode{ my %def = shift->_defaults; return $def{errorcode} ; } sub Exception::Class::Base::_defaults{ return (errorcode => 3); } } use Exception::Class ( 'MyException' => {defaults => {errorcode => 2} }, 'AnotherException' => { isa => 'MyException' }, 'YetAnotherException' => { isa => 'AnotherException', defaults => {errorcode => 5}, }, ); eval { YetAnotherException->throw( error => 'I feel funny.' ) }; my $e; if ( $e = Exception::Class->caught()){ warn $e->error, "\n"; warn $e->errorcode , "\n"; }
update: example added

Replies are listed 'Best First'.
Re^2: switch question
by morgon (Priest) on Jan 06, 2011 at 23:01 UTC
    Maybe your exception classes should implement errorcode()?
    I don't want to do that.

    I use this exceptions in other places as well where this mapping is irrelevant (or maybe I also need a mapping but a different one) and that in this particular case they are used to generate a return-code is not the concern of the exception-class.