![]() |
|
Published 1997-07-01 Printer-friendly version
If you know all about errorcodes, skip this part.
Each time we access a file, a return value is generated which can be queried with the command errorcode(). If errorcode() is zero or false, then the file action was successful. If errorcode() is true then the number returned with errorcode() and the description returned with error() tell us what went wrong. These values vary according to the file access command being used. The Language Reference Manual contains a list of errorcodes for each command.
In my programming experiences I've found differing levels of concern about whether a file error occurs. These have included the following:
SET(Any:ByAnyId,Any:ByAnyId) LOOP NEXT(AnyFile) IF ERRORCODE() THEN BREAK. ! ! multiple lines of wonderful code go here ! END !LOOP
GET(AnyFile,Any:ByAnyId) IF ERRORCODE() MESSAGE('File processing error:' | & '<10,10>' | & 'File: ' & ERRORFILE() & '<10>' | & 'Errorcode: ' & ERRORCODE() & '<10>' | & 'Description: ' & ERROR(), | 'Data File Problem', | ICON:EXCLAMATION,BUTTON:OK,BUTTON:OK,0) END !IFThis generates the window shown in Figure 1.

The procedure name (Saves figuring out which procedure out of many was executing when the error occurred.) This example is for the procedure ProcessCodes.
GET(AnyFile,Any:ByAnyId) IF ERRORCODE() MESSAGE('File Processing Error:' | & '<10,10>' | & 'File: ' & ERRORFILE() & '<10>' | & 'Errorcode: ' & ERRORCODE() & '<10>' | & 'Description: ' & ERROR() | &'<10,10>' | & 'Procedure: ProcessCodes', | 'Data File Problem', | ICON:EXCLAMATION,BUTTON:OK,BUTTON:OK,0) END !IFThis generates the window shown in Figure 2.

GET(AnyFile,Any:ByAnyId) IF ERRORCODE() MESSAGE('File processing error:' | & '<10,10>' | & 'File: ' & ERRORFILE() & '<10>' | & 'Errorcode: ' & ERRORCODE() & '<10>' | & 'Description: ' & ERROR() | &'<10,10>' | & 'Procedure: ProcessCodes' | &'<10>' | & 'Location: After Lookups', | 'Data File Problem', | ICON:EXCLAMATION,BUTTON:OK,BUTTON:OK,0) END !IFThis generates the window shown in Figure 3.

This ended up being a fair amount of code to generate each time. What I wanted was a single template flexible enough to address each of the above levels of concern.
Enter the following code into the file SMPL0001.TPL (or download the template at the top of the article), then register the template.
#TEMPLATE(SMPL0001,'Simple File Error')
#PROCEDURE(FileErrorMessage,'Simple File Error Procedure')
#PROTOTYPE('(<<STRING>,<<STRING>)')
#DISPLAY('')
#DISPLAY('This is a generic file error message procedure')
#DISPLAY('')
#DISPLAY(' Default Procedure is Unspecified')
#DISPLAY(' Default Embed point is Unspecified')
#DISPLAY(' Icon is Exclamation')
#DISPLAY(' Title is File Error')
#DISPLAY('')
#DISPLAY('Possible Calling Conventions:')
#DISPLAY(' O_FileError()')
#DISPLAY(' O_FileError(''Procedure'')')
#DISPLAY('..O_FileError(''Procedure'',''Embed Point'')')
#Display('')
#LOCALDATA
L:Procedure String(30)
L:EmbedPt String(40)
#ENDLOCALDATA
%PROCEDURE %ProcedureType(ErrorProc,ErrorEmbed)
#FOR(%LocalData)
%[20]LocalData %LocalDataStatement
#ENDFOR
CODE
L:Procedure = ErrorProc
IF L:Procedure = ''
L:Procedure = 'Unspecified'
END
L:EmbedPt = ErrorEmbed
IF L:EmbedPt = ''
L:EmbedPt = 'Unspecified'
END
!
! Display message
!
MESSAGE('File processing error:' |
& '<10,10>' |
& 'File: ' & ERRORFILE() & '<10>' |
& 'Errorcode: ' & ERRORCODE() & '<10>' |
& 'Description: ' & ERROR() |
& '<10,10>' |
& 'Procedure: ' & L:Procedure & '<10>' |
& 'Location: ' & L:EmbedPt, |
'Data File Problem', |
ICON:Exclamation,Button:OK,Button:OK,0)
First, add a new procedure to your application.
This should look something like this:

Then, depending on your needs you could call FileErrorMessage as follows and get the following results. Compare the code required and generated results with what we did under levels of concern.
The code fragment...
GET(AnyFile,Any:ByAnyId) IF errorcode() O_FileError() END !IF
...produces the screen:

The code fragment...
GET(AnyFile,Any:ByAnyId)
IF ERRORCODE()
O_FileError('ProcessCodes')
END !IF
...produces the screen:

Finally, the code fragment...
GET(AnyFile,Any:ByAnyId)
IF ERRORCODE()
O_FileError('ProcessCodes','After Lookups')
END !IF
...produces the screen:

Using the above template has provided a flexible, quick, standardized way to handle file error messages. For extended needs the above template could be modified appropriately.
Copyright © 1999-2008 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $189
(includes all back issues since '99)
Renewals from $139
Two years: $289
Renewals from $239