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!
In reply to switch question by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |