in reply to Re^3: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
in thread How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by mr_mischief (Monsignor) on Jan 16, 2007 at 03:11 UTC |
In Section
Seekers of Perl Wisdom