G'day Rolf,
Just throwing a few ideas around.
"... catch error-objects ..."
I'll assume, if $e is the error-object, then 'ref $e' returns "TypeError", "RangeError", and so on.
"... didn't show much implementation ... more interested in comments regarding the interface ..."
I'll use the Try::Tiny syntax. You can implement something else; e.g. there's some alternatives in the "SEE ALSO" section of that module, there's the experimental "Try Catch Exception Handling" introduced in Perl v5.34, and no doubt many more.
Probably in some error handling module, you might have something like:
{ my %dispatch_error; BEGIN { %dispatch_error = ( TypeError => sub { ... handle TypeError exceptions ... }, RangeError => sub { ... handle RangeError exceptions ... } +, ..., '' => sub { ... handle any unspecified exceptions ... }, ); } sub handle_error { my ($e) = @_; my $error_type = ref $e; $error_type = '' unless exists $dispatch_error{$error_type}; $dispatch_error{$error_type}->($e); return; } }
Then your try/catch code could be something like:
try { myroutine(); } catch { handle_error($_); };
So now, the interface in the main code becomes very simple. Beyond whatever try/catch syntax you choose, you can do pretty much whatever you want with the implementation (as long as it has a handle_error() routine).
I would assume your error objects are instantiated from classes with appropriate information; for example, a RangeError class has min and max attributes.
— Ken
In reply to Re: conditional catch-blocks 'try {} catch(COND) { }'
by kcott
in thread conditional catch-blocks 'try {} catch(COND) { }'
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |