On Wed, 1 Nov 2000, Matt Sergeant wrote:
> Definitely use exceptions. I prefer Error.pm for this (sorry, Dave!),
> which allows your handler to simply be:
> 
> sub handler {
>       return try {
>               ...
>       } catch Exception::RetCode with {
>               my $E = shift;
>               return $E->{code};
>       } <other exceptions>
>       ;
> }

Be very careful with nested try/catch blocks.  Error.pm uses prototypes to
make these into anonymous subs, which is usually fine, but this leaks
memory like mad:

my $foo;
try {
    something();
    try {
        $foo++;
    };
} otherwise {
    handle_error();
};

It's not Graham Barr's fault; that's just a byproduct of Perl's support
for closures (I think).

- Perrin

Reply via email to