morgon has asked for the wisdom of the Perl Monks concerning the following question:
I need to map exceptions to error-codes (which will be embedded in a client-response).
Most of the exceptions are instances of Exception::Class-subclasses and the mapping is based on the class-name.
I curently do something like this:
And I find that not very pleasing.my $rc; given($ex) { when($ex->isa("MyException::Class1")) { $rc = 1; } when($ex->isa("MyException::Class2")) { $rc = 2; } default { $rc = 3 } } # and now pass on $rc to a template
Is there a better way to do this?
Or can I do an isa-check via ~~
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: switch question
by roboticus (Chancellor) on Jan 06, 2011 at 23:46 UTC | |
|
Re: switch question
by lamprecht (Friar) on Jan 06, 2011 at 22:24 UTC | |
by morgon (Priest) on Jan 06, 2011 at 23:01 UTC |