in reply to Error.pm -- Design

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.

Replies are listed 'Best First'.
Re^2: Error.pm -- Design
by beckmanel (Novice) on Jul 21, 2006 at 20:49 UTC
    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.

        Because it appears that Error.pm (e.g. run_causes and try) uses these 'features', and they are critical to the program architecture!?
Re^2: Error.pm -- Design
by beckmanel (Novice) on Jul 24, 2006 at 20:40 UTC
    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 }