in reply to Catching errors in closing lexical filehandles
As far as I know, you can't [Added: There is a way, see my other reply below, You *Can* Catch errors in closing lexical filehandles]. Observe,
prints '1', the result of printing to the filehandle.# use Fatal qw/open print close/; use Fatal qw/open close/; my $result = eval { open my $fh, '>', '/dev/full'; print $fh "Foo\n" or die $!; }; print $result ? $result : $@, $/;
Placing an explicit close after the print statement gives something like,
That uses the handy /dev/full device of linux, for which writes always fail with ENOSPC. The failure would have occurred on print if we had set $fh to autoflush or had printed more than a buffersworth of text.Can't close(GLOB(0x804b548)): No space left on device at (eval 2) line + 3 main::__ANON__('GLOB(0x804b548)') called at -e line 1 eval {...} called at -e line 1
For careful error handling, you should close your lexical handles as if they didn't know how to do it for themselves.
Update: gaal++ points out an error. Corrected.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Catching errors in closing lexical filehandles
by gaal (Parson) on Sep 27, 2004 at 05:53 UTC | |
by Zaxo (Archbishop) on Sep 27, 2004 at 05:57 UTC |