http://www.perlmonks.org?node_id=269797


in reply to Re: error handling
in thread error handling

i must have been overanalyzing the problem from the start. i don't know why i didn't think of that.

i did attempt the try...catch thing with Error.pm but it stopped me from doing a return within the block.

thanks!

Replies are listed 'Best First'.
Re: Re: Re: error handling
by argggh (Monk) on Jun 28, 2003 at 20:28 UTC
    This is the mechanism used by Error.pm under the hood, more or less. While Error.pm is a much prettier interface than checking $@ yourself, it has some drawbacks. Since the arguments to both try and catch are anonymous subs, return will return from those and not from the enclosing sub, as you've experienced. You'll have to set up a variable with the value you want to return and then do so outside of try/catch.