Will Coleda (via RT) wrote:

I would expect both of these programs to output the same thing, but it
looks like rethrow is generating the same output that throw would
here.

What is the difference supposed to be between these two ops?

The two ops are intentionally almost entirely the same. The only difference is that 'throw' creates a new iterator of exception handlers, while 'rethrow' pulls the next exception handler off the iterator. So, 'rethrow' cannot be called on an exception that hasn't been thrown before. And if 'throw' is called on an exception that's already been thrown before, it will return to the first exception handler again, instead of the next exception handler in the chain of handlers.

$ cat foo.pir
sub foo :main
  bar()
end

sub bar
  baz()
end

sub baz
  die "eek"
end

$ ../../parrot foo.pir
eek
current instr.: 'baz' pc 24 (foo.pir:10)
called from Sub 'bar' pc 19 (foo.pir:6)
called from Sub 'foo' pc 7 (foo.pir:2)
$ cat bar.pir
sub foo :main
  push_eh eh
    bar()
  pop_eh
  end

eh:
  .get_results($P0)
  rethrow $P0
end

sub bar
  baz()
end

sub baz
  die "eek"
end
$ ../../parrot bar.pir
eek
current instr.: 'foo' pc 16 (bar.pir:9)

I don't understand the problem. Is it that you expect 'rethrow' to keep the stack trace of the original 'die'?

Allison

Reply via email to