On Jul 26, 2013, at 1:56 AM, David Nicol <davidnicol@gmail.com> wrote: >> package Foo { >> CATCH { >> # BOOM. >> } >> } > > that looks like it should get optimized out, with a warning: AFAIK > Perl has no syntax construct at this time that would change the scope > of something depending on if something else is there or not. > > package Foo { > CATCH { > ... recovering from Foo:: error ... > } > } > package Foo { > sub riskything{ > ... > }; > CATCH { > ... recovering from error in Foo::riskything() > } > } Yeah, that’s what I meant. Should also allow: package Foo { use Bar; my $f = Bar->baz; CATCH { # Recover from error anywhere in Foo } } > Another question -- where does a package-scoped Catch return its value > to? -- I imagine the answer would be, at the call stack boundary > between the package that caught the error and a different package that > called it. Who says it has to return a value? It is a block, not a subroutine. > That would support conventions such as returning -1 for errors > implemented like so: > > FancyNewNetworkLibrary::CATCH { warn "unhandled exception ".shift @@; -1 } Hrm. I see what you mean. If, in your above example, CATCH handles an error in riskything(), what gets returned from riskything()? Best, DavidThread Previous | Thread Next