Luke Palmer <[EMAIL PROTECTED]> writes:

> On 9/25/05, Yuval Kogman <[EMAIL PROTECTED]> wrote:
>> I propose a new model - each exception has a continuation that
>> allows it to be unfatalized.
> I think we've already talked about something like this.  But in the
> presence of "use fatal", it makes a lot more sense.
> Something comes to mind:
>     use fatal;
>     sub foo()  { bar()  }
>     sub bar()  { baz()  }
>     sub baz()  { quux() }
>     sub quux() { fail }
>     {
>         say foo();
>         CATCH { $!.continue(42) }
>     }
> Exactly which exception is continued?

The bottommost one. If you want to return to somewhere up its call chain, do:


Assuming caller returns a continuation (which I still fondly hope it will). I'm
assuming you're examples aren't necessarily tail calls of course. 

> Where do we cut off the call chain and replace our own value?  This comes up
> again with open().  Let's say open is implemented with a series of five
> nested calls, the innermost which knows how to fail and propagate outwards.
> However, the programmer using open() has no idea of its internals, so it
> ought to override the return value of open() itself, rather than its utility
> functions.  However, we can't go with outermost, because then you'd only be
> "fixing" the lexical call ("say foo()" above).  So it's somewhere in between.
> Where?

Obviously the topmost function should do:

  sub open(...) {
    CATCH { $!.rethrow }

This assumes that 'rethrow' throws a new exception that delegates to the
original exception for lots of its behaviour. If, later, you want to explicitly
get at the exception thrown by the helper function, you could do something


Piers Cawley <[EMAIL PROTECTED]>

Reply via email to