Mailme.4gl - Error routine
Posted in 1994
Dear All,
First of all I would like to thank Jack Parker, Alan Popiel
and Dave Snyder for kindly reviewing the following routine
before posting to the net. All three have made constructive
suggestions as to where I might improve the routine and when
I have done so I will repost.
On the subject of error routines here is my contribution to
the discussion. It currently does not answer all four of
Jack's requirements but it goes someway to deal with points
c & d.
For a little while I have been trying to find an intermittent
bug in an Informix 4GL program without success. I had put in
lots of error messages in the hope the users would pass these
on.
After waiting in vain for the error messages I came up with this
simple routine which mails me whenever an error has occurred.
It is based around the example code from Informix but the idea is
mine and could be useful for people on different sites.
It could be improved to use the data structure which informix
uses to print errors if I knew how to get hold of it but its fairly
simple to use. The following are suggestions to improve the routine.
1) It should fill in the (%s) in the error message from the
SQLCA.SQLERRM message.
2) The line number should maybe be replaced by a more generic
message such as "Select * from" since this would avoid having
to modify the parameters if the code changes.
3) The mail message sent should have the subject field set
indicating where abouts the error occurred.
4) Also the message should indicate who last modified the code
5) The mail address should be an alias which would avoid recompiling
if the person moved etc.
I'm sure there are better ways of catching errors but I felt this
was quite neat and it caught my bug which was a memory allocation
error # -208 which was not caught by startlog().
I hope that this might aid someone starting out with Informix.
Cheers
Peter
The following program mailme.4gl should demonstrate the function just
edit my userid in the function call to your own. In actual use this
should be an alias to the system developer.
I hope you don't have a patients table in your stores database. :-)
--
Peter K. Botcherby
Division of Medical & Molecular Genetics
Guys Hospital, London, UK. p.botcherby@uk.ac.umds
-----------------------Cut Here---------------------------------
# Mailme.4gl
DATABASE stores
MAIN
WHENEVER ERROR CONTINUE
SELECT * FROM patients
IF ( status ) THEN
CALL mail_error( 6,"in main()","p.botcherby@uk.ac.umds" )
END IF
WHENEVER ERROR STOP
END MAIN
################################################################
## ##
## Function mail_error( line_no, fname, userid ) ##
## ##
## line_no : the line number where the error occurred ##
## fname : the function in which the error occurred ##
## userid : the id of the person to be mailed the error ##
## ##
## lv_command : command line argument for the "run" command ##
## ##
## This function will collect the error messages that are ##
## given in the parameters and derived from the SQLCA record ##
## and build them into a command line argument for the run ##
## command which is then executed and mails the message to ##
## the userid. ##
## ##
## Beware : The order of quotes and newlines is tiresome ##
## : and they can drive you mad. ##
## ##
## Author : Peter K. Botcherby 01-Mar-1994 ##
## : #include <disclaimer.h> ##
## ##
################################################################
FUNCTION mail_error( line_no, fname, userid )
DEFINE line_no SMALLINT,
fname CHAR(20),
userid CHAR(30),
isam_err INTEGER,
errtxt CHAR(70),
pos SMALLINT,
lv_command CHAR(255)
INITIALIZE lv_command TO NULL
LET isam_err = SQLCA.SQLERRD[2]
CALL ERR_GET(SQLCA.SQLCODE) RETURNING errtxt
################################################################
## The following line gets rid of an offending "\\n" ##
## which is tacked on to the end of the string returned by ##
## Informix routine ERR_GET() and splits the command line ##
################################################################
let pos = length(errtxt) let errtxt[pos] = " "
let lv_command = "echo 'Function: ",fname clipped, " line # ",
line_no using "-<<<<<","\\\\","\\n","Error Number: ", SQLCA.SQLCODE
using "-<<<<<", " ISAM Error: ", isam_err using "-<<<<<&","\\\\","\\n",
"Error message: ","\\\\","\\n",
errtxt,"\\'\\"""| mail ", userid clipped,"\\""""
run lv_command
END FUNCTION
-------------------Cut Here-------------------------------------
Example output of mailme
From pkb@pru1 Tue Mar 1 13:24:50 1994
Return-Path: <pkb@pru1>
Date: Tue, 1 Mar 94 13:24:48 GMT
From: pkb@pru1 (Peter Botcherby)
Message-Id: <9403011324.AA17847@genetics>
To: p.botcherby@miranda
Content-Length: 153
X-Lines: 4
Function: in main() line # 6
Error Number: -206 ISAM Error: -111
Error message:
The specified table (%s) is not in the database.