Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: switch question

by lamprecht (Friar)
on Jan 06, 2011 at 22:24 UTC ( [id://880956]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://880956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2026-04-21 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.