Kbase 6589: Access to messages and errors/How to trap errors using _MSG
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
Access to messages and errors/How to trap errors using _MSG
911021-ptg01There is an undocumented function in PROGRESS 4GL _MSG. _MSG returns
the message number in the message stack that is specified by its
integer function.
e.g.,
_MSG(1) returns last message
_MSG(2) returns message before that
If _MSG returns ? then there are no further entries on the stack
at that point.
The following program is an example of the use of the _MSG function.
It determines the the last message received at by the client process
and searches the messages file for the test of that message and then
redisplays that text.
/* ---- Beginning of PROGRAM --- */
define variable LCV as integer no-undo.
define variable FILE-NUMBER as integer no-undo.
define variable MSGFILE as character no-undo.
define variable MSGNBR as integer no-undo.
define variable MSGNUMBER as character no-undo.
define variable POSITION as integer initial 0 no-undo.
define variable MSGTEXT as character
format "x(78)" no-undo.
hide all no-pause.
assign MSGNBR = _msg(1)
FILE-NUMBER = (truncate((MSGNBR - 1) / 50, 0) + 1)
MSGFILE =
search("prohelp/msgdata/msg" + string(FILE-NUMBER)).
if MSGFILE = ? /* cannot locate the MESSAGES file in PROPATH */
then message "SYSTEM ERROR: cannot find message file".
else do:
input from value(MSGFILE) no-echo.
IN-BLOCK:
do on endkey undo IN-BLOCK, leave IN-BLOCK:
assign POSITION = (MSGNBR - 1) modulo 50.
do LCV = 1 to POSITION:
import.
end.
import MSGNUMBER MSGTEXT.
end.
input close.
input from terminal.
if integer( MSGNUMBER) <> MSGNBR
then message "SYSTEM ERROR : System Error Text out of Sync.".
else message MSGTEXT.
pause.
end.
pause 0 no-message.
/* ---- End Of Program --- */
Another use of _MSG would be to determine if an error has occurred
so that we can program around the errors. This example requires that
we have pre-compile all procedures except one, which contains a logical
flaw that will trigger a compile time error. In the following program
we are going to cause an error since we are attempting to assign an
integer value to a character which will cause _MSG(1) = 196 and
_MSG(2) = 223 if we attempt to run it. We will call t1.p.
def var x as char.
def var y as int.
x = y.
Our calling procedure looks like this. Notice the input and output
statements. These will prevent error statements from displaying
on the message line of the screen when we run t1.p. After we
run our program, we will check for errors and display the numbers
of all that occurred.
define variable LCV as integer no-undo.
output to /dev
ull.
input from /dev/tty.
run t1.p.
input from terminal.
output to terminal.
run someprogram.p
if _MSG(1) <> 196 and _MSG(2) <> 223
then repeat :
LCV = LCV + 1.
if _MSG(LCV) <> 196 and _MSG(LCV + 1) <> 223
then message "Error " _MSG(1) "has occurred".
else leave.
end.
Progress Software Technical Support Note # 6589