kiat has asked for the wisdom of the Perl Monks concerning the following question:
This is related to my node at Trap errors in entire module.... I've the following code at the beginning (after the shebang line) of my main script to trap compile-time errors in all the modules. During development, the errors are directed to the browser for debugging. In production, the errors are written to a trap error file and a customised error message is displayed on the browser to "enlighten" the user.
#!C:/perl/bin/perl.exe # scriptname: index.pl BEGIN { my $development = 0; if ($development) { use CGI::Carp qw(fatalsToBrowser); } else { use CGI::Carp qw(fatalsToBrowser set_message carpout); open(LOG, ">>datadir/trap_error") or die("Unable to open mycgi_log: $!\n"); carpout(LOG); sub handle_errors { print "<h1>Script Error</h1>"; print qq~<p>An error occurred while processing your request. +This error has been noted and appropriate action will be taken to rec +tify it.</p>~; } set_message(\&handle_errors); } } use Mymodule1; use Mymodule2; my $query = get_param('node') || 'start'; # Rest of code in the main script...
1) Is it necessary to write the errors to a file? Should I just examine the error.log periodically?
2) If the trap error file is necessary, how do I ensure that it will be kept to a certain size so that there's no risk of it becoming bloated?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trap errors at BEGIN
by matija (Priest) on Mar 29, 2004 at 05:46 UTC |