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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.