Hi, Toby.
Thanks for reporting this.
As you say, it works if warnings are enabled, and has done since perl 5.6.1:
$ perldoc perl561delta:
Show quoted text> Failures in DESTROY()
> When code in a destructor threw an exception, it went unnoticed
> in earlier versions of Perl, unless someone happened to be
> looking in $@ just after the point the destructor
> happened to run. Such failures are now visible as warnings
> when warnings are enabled.
$ cat test.pl
01 use strict;
02 use warnings;
03 use v5.14;
04
05 use Scope::Guard;
06
07 $|++;
08
09 do {
10 my $guard = Scope::Guard->new(sub { say "Hello"; die "Goodbye"; });
11 42;
12 };
$ perl ./test.pl
Useless use of a constant (42) in void context at test.pl line 11.
Hello
(in cleanup) Goodbye at test.pl line 10.
I'm happy to consider a documentation patch which mentions this, but otherwise I think "don't do that then" applies :-)
$ perldoc perlstyle
Show quoted text> The most important thing is to run your programs under the -w flag at
> all times. You may turn it off explicitly for particular portions of
> code via the "no warnings" pragma or the $^W variable if you must.
> You should also always run under "use strict" or know the reason why
> not.