Subject: | Undoccumented $@ (eval/die) behaviour. |
Had a chance to use Inline::Java::Handle recently.
First thing: it worked! : )
But, i've spent a lot of time trying to understand, why some of my
errors aren't propagated. I discovered, that when using
Inline::Java::Handle, the error message - $@ - is cleared when the
handlers are closed. This is disastrous, becouse by default they are
closed automatically upon an exit from the subroutine, and it renders
any exceptions inside the subroutine invisible. This property should be
at least docummented, becouse it is then possible to workaround.
Example code:
sub foo {
local *STDIN = new Inline::Java::Handle($in);
local *STDOUT = new Inline::Java::Handle($out);
die "bar";
}
eval {foo();};
report($@) if $@;
The workaround:
sub foo {
local *STDIN = new Inline::Java::Handle($in);
local *STDOUT = new Inline::Java::Handle($out);
eval { die "bar"; };
my $err = $@;
close(*STDOUT);
close(*STDIN);
die $err if $err;
}
eval { foo(); };
report($@) if $@;