On Mon, Dec 08, 2008 at 02:32:14PM -0600, Patrick R. Michaud wrote: : A very interesting question came up on #perl today, so I'm : forwarding it to p6l for discussion/decision. : : Given the following code: : : sub foo() { return 1; } : sub bar() { warn "oops"; } : : { : CONTROL { ... } : foo(); : bar(); : } : : S04 seems to clearly indicate that the CONTROL block above would : be invoked by the C<warn> exception thrown by bar(). The #perl6 : question is, do the same semantics apply for C<return> -- i.e., : would the return exception thrown in foo() also invoke the : CONTROL block in the caller? : : Both interpretations have validity, which is why I'm bringing : it here for further reflection and guidance.
foo()'s implicit CONTROL handles the return after checking that the exception's target context happens to match &?ROUTINE, so the outward search for a handler terminates at that point. Doing it the other way would make it impossible to optimize return into a goto end-of-routine. Unlike warn, return is normal control flow, and we need to be careful not to mandate largely useless overhead. Larry