Hi monks,

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...
My questions are:

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?


In reply to Trap errors at BEGIN by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.