B
Bennett Haselton
I wrote the following script to test whether, if I try writing to an
invalid filehandle, the error message would get sent to the browser:
#!/usr/bin/perl
use strict;
use IO::File;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
# This will not open a valid filehandle since the script runs as
nobody
my $fh = IO::File->new("> doesnotexist.txt");
print $fh "foo";
die "Die here, if you get this far";
The line 'print $fh "foo";' does generate an error, however that error
gets written to /var/log/httpd/error_log where it says "Can't use an
undefined value as a symbol reference at /var/www/html/carptest/open-
wrong-file-with-carp-fatalstobrowser.cgi line 11". I want that sent
to the *browser*, not written to the log file. The line 'die "Die
here, if you get this far";' never gets executed.
The CGI::Carp page says that "Nonfatal errors will still be directed
to the log file only". But isn't the file handle error a *fatal*
error, since it caused the script to exit before getting to the 'die
"Die here, if you get this far";' line? And if it's a fatal error,
why didn't it get sent to the browser?
invalid filehandle, the error message would get sent to the browser:
#!/usr/bin/perl
use strict;
use IO::File;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
# This will not open a valid filehandle since the script runs as
nobody
my $fh = IO::File->new("> doesnotexist.txt");
print $fh "foo";
die "Die here, if you get this far";
The line 'print $fh "foo";' does generate an error, however that error
gets written to /var/log/httpd/error_log where it says "Can't use an
undefined value as a symbol reference at /var/www/html/carptest/open-
wrong-file-with-carp-fatalstobrowser.cgi line 11". I want that sent
to the *browser*, not written to the log file. The line 'die "Die
here, if you get this far";' never gets executed.
The CGI::Carp page says that "Nonfatal errors will still be directed
to the log file only". But isn't the file handle error a *fatal*
error, since it caused the script to exit before getting to the 'die
"Die here, if you get this far";' line? And if it's a fatal error,
why didn't it get sent to the browser?