doy / try-tiny

minimal try/catch with proper preservation of $@
http://metacpan.org/release/Try-Tiny
10 stars 15 forks source link

Set $@ within catch {} #25

Open FGasper opened 8 years ago

FGasper commented 8 years ago

The fact of using $_ rather than $@ within catch {} blocks has a couple of unfortunate effects:

1) You lose access to $ from outside the try/catch. This has never really bothered me, but I could see it bugging someone who uses $ in iterations more than I do.

2) Setting $@ is the only way to get PROPAGATE from Perl exceptions. The fact that T::T uses a different variable makes anyone who wants PROPAGATE to do local $@ = $_; within every catch {} where we might potentially rethrow the exception. This is annoying.

I propose a flag, and/or some other means, of telling Try::Tiny to set a local()ized $@ as the exception variable within catch {} blocks.

Thoughts?

karenetheridge commented 8 years ago

surely propagating the exception is as easy as die $_; ?

FGasper commented 8 years ago

@karenetheridge No, because that doesn’t fire PROPAGATE.

cf. perldoc -f die