Onerr – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 175

Advertising
background image

Chapter
Statements

11

11 -23

Use the ONERR statement to handle arithmetic errors, if they occur, during
program execution. The ONERR statement only traps arithmetic overflow
(value too large), arithmetic underflow (value too small), divide by zero,
and bad argument errors. All other errors are not trapped and cause the
BASIC module to enter the Command mode. If an arithmetic error occurs
after you execute the ONERR statement, the module interpreter passes
control to the line number (ln num) following the ONERR statement.
You handle the error condition in a manner suitable to your application.
The ONERR command does not trap bad data entered during an input
instruction. This yields a

TRY AGAIN

message or

EXTRA IGNORED

message.

For expanded ONERR functionality, refer to CALL 38 on page 12 -36.
Note: This statement did not work in the Series A module.

After you execute the ONERR statement, you can determine what type of
error occurred by examining external memory location 257 (101H).
The error codes are:

ERROR CODE = 10–DIVIDE BY ZERO

ERROR CODE = 13–DIVIDE SYNTAX ERROR

ERROR CODE = 20–ARITH. OVERFLOW

ERROR CODE = 30–ARITH.UNDERFLOW

ERROR CODE = 40–BAD ARGUMENT

You can examine this value by using an XBY(257) special function
operator (page 9 -19). In addition, the line number can be determined by
this BASIC line 256*XBY(69FDH)+XBY(69FEH).

Syntax

ONERR

ln num

Example

>1 REM EXAMPLE PROGRAM

>10 ONERR 500

>20 FOR I = 5 TO 0 STEP –1

>30 PRINT 1/I

>40 NEXT I

>50 END

>500 PRINT “ERROR CODE WAS ”,XBY(257)

>510 PRINT ”AT LINE ” (256*XBY(69FDH)+XBY(69FEH))

>510 END

READY

>RUN

.2

.25

.33333333

.5

1

ERROR CODE WAS 10

AT LINE 30

ONERR

A GOTO statement (page 11 -14) can replace
the END statement (page 11 -10) in this
example to provide a method of user
programmed error recovery.

Advertising