beckmanel has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone give a brief overview of how this module works? There's syntax and usage here that I'm sure is ovbious to Monks, but less so to novices. Thank You.

Replies are listed 'Best First'.
Re: Error.pm -- Design
by ikegami (Patriarch) on Jul 21, 2006 at 16:47 UTC

    I'm not sure what you want. Hopefully, this will help.

    Thanks to indirect object syntax,

    catch Error::IO ...

    is the same as

    Error::IO->catch(...)

    Thanks to try and with's prototype,

    try { ... } catch Error::IO with { ... };

    is the same as

    try(sub { ... }, Error::IO->catch(with(sub { ... })));

    (That's why the trailing ; is necessary.)

    In fact, the following would work:

    sub stuff { ... } sub err_handler { ... } try \&stuff, catch Error::IO with \&err_handler;

    try uses eval BLOCK to catch exceptions (i.e. calls to die). It determines what to do with the caught exception using the object catch returns. throw is a wrapper around die.

      Thanks much -- it also appears that given the &;$ try prototype that all the succeeding blocks create a hash of the block names, and if there are multiple instances of a given block name (e.g. catch), the hash element is an array of the blocks!? Is this documented anywhere?

        Is this documented anywhere?

        No idea. Why do you want to know? Very few modules document how they achieve their ends.

      You've been more than kind and patient; this will be the last question on this topic; promise. I'm trying to figure out how the variable 'clauses' is built. Several routines pass back a lexical variable, but I'm not seeing where the combined hash is generated? thanks again.

        catch, finally, except and otherwise build $clauses much in the same manner as the following build_list builds $list.

        sub build_list { my $item = shift; my $list = shift || []; unshift(@$list, $item); return $list; } { # Without parens: my $list = build_list 'a', build_list 'b', build_list 'c'; print(@$list, "\n"); # abc } { # With parens: my $list = build_list('a', build_list('b', build_list('c'))); print(@$list, "\n"); # abc } { # Spelled out: my $list; $list = build_list 'c'; $list = build_list 'b', $list; $list = build_list 'a', $list; print(@$list, "\n"); # abc }
Re: Error.pm -- Design
by diotalevi (Canon) on Jul 21, 2006 at 17:49 UTC

      I think perrin's post may be out of date. There have been over half-a-dozen releases this spring closing various RT bugs and stabilizing it. That said, I think Exception::Class has more mileage on it and may be a better choice.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        No, I'm afraid all of my warnings about Error still apply. They are fundamental issues with the design and the limitations of perl's sub prototypes.