On Tue, Jul 23, 2013 at 2:04 PM, David Golden <xdg@xdg.me> wrote: > > that isa 'FOO'). However, if the exception needs to be parked in a > global, I'd park it in $@ for consistency with what happens outside > try/catch. I nominate @@ for the stack of new exceptions, for consistency without interference. A "Yoda's exception system" (in which, drumroll please, there is no try) can be effected with a DEFER block. C< catch FooE { ... } > might essentially expand into something like OnScopeExit { # before, after, or during reassignment of locals? my @CatchMe, @NewStack; push @{ $_->isa('FooE') ? \@CatchMe : \@NewStack }, $_ for @@; for ( @CatchMe ) { ... }; @@ = @NewStack; # any advantage to *@ = \@NewStack ??? } Why a stack, instead of just one variable? To handle situations where deferred code throws another exception, as well as exceptions thrown from DESTROY routines, thus avoiding the problems caused clearing an unlocalized $@. The big difference between $@ and the above-proposed @@ has to do with clearing it: $@ gets cleared on all C<eval> calls; @@ would only get items removed from it when they are explicitly consumed, either by convention or by restricting access to it. Further compatibility could be provided with sub YodaTry(&) { eval { shift ->() ; 1 } or push @@, $@ } I see how one could create a pure-perl YodaCatch, using the hack from Scope::local_OnExit, but the syntax would wind up looking like local @YodaCatch = ( FooE => sub { ... }, );Thread Previous | Thread Next