That seems to be the only reliable approach. You don’t even need to load IO::Handle. However, I can’t actually get it to complain:
use strict; sub IO::Handle::DESTROY { my $self = shift; warn +(caller 0)[3]."($self)\n"; close $self or die "$!\n"; } { if( open my $fh, ">", "/dev/full" ) { print { $fh } 1 } } warn "Terminating\n"; __END__ IO::Handle::DESTROY(IO::Handle=IO(0x8130c0c)) Terminating
The error does occur: if I change the die to a warn, I see the warning. But while die aborts execution (statements after it will not run), I can’t make it throw an exception. The conditions from Carping in DESTROY, which was mentioned in another subthread, do not apply either.
Makeshifts last the longest.
In reply to Re^4: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by Aristotle
in thread How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by Aristotle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |