exception (version 2.3)

You can also look at:
#! /usr/bin/perl

##############################################################################
#
# SYNTAX: exception caller level message
#
# DESCRIPTION: A general exception handling routine. All errors should
# DESCRIPTION: eventually be reported through this routine.
#
# VERSION: 2.3
#
# HISTORY: 0.0 -> 1.0 10/17/96
# HISTORY: Fixed a bug which left out the closing anchor tag in the
# HISTORY: error log entry.
# HISTORY:
# HISTORY: 1.0 -> 1.1 12/15/97
# HISTORY: Added a fatal error flag to the par file.
# HISTORY: 
# HISTORY: 1.1 -. 2.0 1999-05-07
# HISTORY: Converted from ksh to perl
# HISTORY: 
# HISTORY: 2.0 -> 2.1 1999-06-14
# HISTORY: Fixed bug which caused errors to not be written to the error log.
# HISTORY: 
# HISTORY: 2.1 -> 2.2 1999-06-28
# HISTORY: Added code to increment nprocerrors parameter in job.par.
# HISTORY: This is to facilitate automated error checking.
# HISTORY: Added a call to $UTIL/kill_processing for level 3 or higher
# HISTORY: errors to make these truly fatal.
# HISTORY: 
# HISTORY: 2.2 -> 2.3 199-07-28
# HISTORY: Now explicitly close log file handles to flush the log output
# HISTORY: in the event of a fatal error.
#
# CALLS: $UTIL/generate_filename
# CALLS: $UTIL/set_parameter
#
##############################################################################

use File::Basename;

($caller, $level, $message) = @ARGV;

$FTOOL=   $ENV{"FTOOL"};
$UTIL =   $ENV{"UTIL"};
$JOBPAR = $ENV{"JOBPAR"};
$ERRLOG = $ENV{"ERRLOG"};

$caller_base = basename($caller);

##################################
# Get job log and error log names
##################################
chomp($joblog = `$UTIL/generate_filename joblog`);
chomp($errlog = `$UTIL/generate_filename errlog`);

#################################
# HTML anchor name for the error
#################################
chomp($lbldat = `date '+%dE%H%M%S'`);
$label = "E$lbldat";

################
# Job log entry
################
open JOBLOG, ">>$joblog";
print JOBLOG "<H2><A NAME=\"${label}\">";
print JOBLOG "E${level} in ${caller_base}: ${message}</A></H2>\n";
close JOBLOG;

##################
# Error log entry
##################
open ERRLOG, ">>$errlog";
print ERRLOG "  <LI><A HREF=\"${joblog}#${label}\">";
print ERRLOG "E${level} in ${caller_base}: ${message}</A>\n";
close ERRLOG;

######################################
# Increment nprocerrors in the jobpar 
######################################
chomp($nerrors=`$FTOOL/pget ./$JOBPAR nprocerrors 2>>$joblog`);
$nerrors++;
`$FTOOL/pset ./$JOBPAR nprocerrors=$nerrors 2>>$joblog`;

###############################################
# Set the fatal error flag in the par file for
# level three or higher errors
# such an error is fatal so kill it!
###############################################
if ( $level >= 3 ) {
    system("$UTIL/set_parameter $JOBPAR proc_error yes");

    system("$UTIL/kill_processing");
}

exit 0;