Download HP BASIC for OpenVMS User Manual

Transcript
15.2.5.5 Determining OpenVMS Error Information
HP BASIC provides a built-in function, VMSSTATUS, that returns the
originally signaled error before it is translated to a BASIC error. For example,
for the BASIC error ‘‘End of file on device’’ (ERR=11), the VMSSTATUS
function returns ‘‘RMS$_EOF’’ (RMS end of file). This function is useful when
the error is NOTBASIC (ERR=194).
When there is no error pending, VMSSTATUS is undefined. The value
returned by this function is the actual signaled error value. If non-BASIC
errors are being handled, the VMSSTATUS function might be the only way to
find out which error caused the exception.
The following example shows a program that performs file I/O. The first WHEN
ERROR block traps any errors that occur while the program is opening the file
or requesting user input. The detached handler for this block checks the
value of VMSSTATUS to determine the exception that occurred. The inner
error handler handles two special errors, BAS$K_RECNOTFOU and BAS$K_
RECBUCLOC, separately. If the error signaled does not correspond to one of
these, the inner error handler passes control to the outer handler with the
EXIT HANDLER statement. The outer handler sets the program status to
VMSSTATUS. When the program exits, the operating system displays any
status that is of warning severity or greater.
PROGRAM Tester
OPTION HANDLE = ERROR
EXTERNAL LONG CONSTANT BAS$K_RECNOTFOU, BAS$K_RECBUCLOC
DECLARE LONG Final_status
MAP (Rec_buffer)
&
STRING Rec_key
= 5,
&
STRING Rest_of_record = 20
Final_status = 1
WHEN ERROR USE Global_handler
OPEN "My_database" FOR INPUT AS FILE #1 &
,INDEXED FIXED
&
,ACCESS READ
&
,MAP Rec_buffer
&
,PRIMARY Rec_key
Get_key:
INPUT "Record to retrieve"; Rec_key
WHEN ERROR IN
GET #1%, KEY #0 EQ Rec_key
PRINT Rest_of_record
USE
SELECT ERR
CASE = BAS$K_RECNOTFOU
PRINT "Record not found"
CONTINUE Get_key
Handling Run-Time Errors 15–15