Guidance
指路人
g.yi.org
Software / Reginald / Examples / Errors.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* Shows various ways of getting feedback on REXX Dialog errors */

/* Cause an error with REXX Dialog's RXMSG() function. (We're trying to perform
 * a PROCESS operation upon a window that doesn't exist. We should get the
 * "Can't find REXX window: MyWindow' error message returned). We get an error
 * string back, and also REXX Dialog automatically displays a message box,
 * because those are the defaults.
 */
err = RXMSG('MyWindow')
CALL RXSAY('RXMSG() returned '||err)

/* Do the same error, but this time ask to be returned an error number. We
 * haven't changed the default group errors to be reported, and we specify
 * DISPLAY option, so REXX Dialog is still going to display that message box.
 */
CALL RXERR('NUM|DISPLAY')
err = RXMSG('MyWindow')
CALL RXSAY('RXMSG() returned '||err)

/* Do the same error, but this time change the error groups to '' (ie, REXX
 * Dialog does not do any display or condition raising for any errors). We're
 * going to get the error message returned, but REXX Dialog isn't going
 * to display that message box.
 */
CALL RXERR('', '')
err = RXMSG('MyWindow')
CALL RXSAY('RXMSG() returned '||err)

/* Do the same error, but this time change the error groups to '' and ask
 * for an error number return. Again, REXX Dialog isn't going to display
 * that message box.
 */
CALL RXERR('NUM', '')
err = RXMSG('MyWindow')
CALL RXSAY('RXMSG() returned '||err)

/* Let's ask for ERROR option, and turn all error groups on. When the error
 * occurs on this call to RXMSG(), REXX Dialog will raise ERROR condition. We
 * can trap that via SIGNAL or CALL (or ignore it by turning off ERROR trapping).
 * In our ERROR condition handler, SIGL is set to the line number were we made
 * the failed call to our REXX Dialog function (ie, RXMSG() below).
 * SOURCELINE(SIGL) will give us the text upon that line. CONDITION('D') will
 * give us the error message that the REXX Dialog function would have returned
 * to us if we didn't have the ERROR option. And CONDITION('E') will give us the
 * error number that normally would have been returned by the REXX Dialog
 * function if we had NUM but not ERROR. We're going to ask REXX Dialog to
 * display the message for us via the DISPLAY option.
 */
SIGNAL ON ERROR NAME bad1

CALL RXERR('ERROR|DISPLAY', '~')
err = RXMSG('MyWindow')
CALL RXSAY("REXX Dialog didn't raise ERROR!")

resume1:

/* Let's ask for the SYNTAX option. When the error occurs on this call to
 * RXMSG(), REXX Dialog will raise SYNTAX condition. We need to trap that, or
 * else the REXX interpreter will abort our script. In our SYNTAX handler,
 * SIGL is set to the line number were we made the failed call to our REXX
 * Dialog function (ie, RXMSG() below). SOURCELINE(SIGL) will give us the
 * text upon that line. CONDITION('D') will give us the error message that
 * the REXX Dialog function would have returned to us if we didn't have the
 * SYNTAX option. And CONDITION('E') will give us the error number that normally
 * would have been returned by the REXX dialog function if we had NUM but not
 * SYNTAX. We'll display the error message ourselves, but we could have asked
 * REXX Dialog to do that for us (for REXX Dialog errors only -- not SYNTAX
 * errors generated from other functions) by specifying the 'DISPLAY' option.
 */

SIGNAL ON SYNTAX NAME bad2

CALL RXERR('SYNTAX', '~')
err = RXMSG('MyWindow')
CALL RXSAY("REXX Dialog didn't raise SYNTAX!")

resume2:

SIGNAL ON SYNTAX NAME bad3

/* Cause a runtime SYNTAX error. In this case, we deliberately pass a bad option
 * to the TIME() built-in. So REXX will generate SYNTAX and we will post our RXSAY()
 * message box. You really have no control over ignoring SYNTAX errors that are
 * generated by other than calls to REXX Dialog functions. For this, you're always
 * going to see the RXSAY message box regardless of how you set RXERR(). RXERR()
 * controls only the error handling behavior of REXX Dialog functions
 */
CALL TIME('A')

EXIT

/* Trapping SYNTAX as raised by REXX Dialog */
bad2:
/*
   linenum = SIGL
   CALL RXSAY(CONDITION('D') || '0D0A0D0A'X || SOURCELINE(SIGL),,'SYNTAX Error '||CONDITION('E')||' at line '||SIGL)
*/
   CALL CONDITION('M')
   SIGNAL resume2

/* Trapping SYNTAX as raised by TIME() */
bad3:
/*
   linenum = SIGL
   CALL RXSAY(CONDITION('D') || '0D0A0D0A'X || SOURCELINE(SIGL),,'SYNTAX Error '||CONDITION('E')||' at line '||SIGL)
*/
   CALL CONDITION('M')
   EXIT

/* Trapping ERROR as raised by REXX Dialog */
bad1:
   SIGNAL resume1
掌柜推荐
 
 
¥900.00 ·
 
 
¥880.00 ·
 
 
¥497.00 ·
 
 
¥380.00 ·
 
 
¥980.00 ·
 
 
¥1,080.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:02