Fox has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks

So, I was playing with exceptions and trying to re-throw an exception:
try { die "test"; CATCH { say $!; die "exp: [$!]"; } }
but this hangs, and the output:
test exp: [test] exp: [exp: [test]] exp: [exp: [exp: [test]]] exp: [exp: [exp: [exp: [test]]]] exp: [exp: [exp: [exp: [exp: [test]]]]] exp: [exp: [exp: [exp: [exp: [exp: [test]]]]]] exp: [exp: [exp: [exp: [exp: [exp: [exp: [test]]]]]]] . . .
looks like the CATCH block is re-catching the new exception ? I expected it would throw the exception to an outer scope, am I doing something wrong here ? how can I accomplish that ?

Replies are listed 'Best First'.
Re: perl6: exceptions
by moritz (Cardinal) on Sep 15, 2010 at 12:04 UTC
    looks like the CATCH block is re-catching the new exception ?

    Indeed that's what happens; it's a known (and long standing) bug in Rakudo.

    I expected it would throw the exception to an outer scope, am I doing something wrong here ?
    Your expectations are fine, and in line with the specification.
    how can I accomplish that ?

    You can either fix the bug in Rakudo, or work around it with something like

    my $rethrow; try { die "test"; CATCH { say $!; $rethrow = $! } } die $rethrow;

    I'm sorry for the inconvenience.

    Perl 6 - links to (nearly) everything that is Perl 6.
      ahh thanks again Moritz, and you don't have to be sorry ! I'm just playing around with rakudo. and I should learn to search the bugtracker.