Onerr, Onerr -12, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 108: Syntax

Advertising
background image

Publication 1746-RM001A-US-P

8-12 Execution Control and Interrupt Support Functions

>20

GOSUB 100

>30

NEXT I

>40

END

>100 REM USER SUBROUTINE HERE

>105 PRINT I,

>110 GOSUB 200

>120 RETURN

>200 REM START OF NESTED SUBROUTINE

>210 PRINT I*I

220 RETURN

READY

>RUN

1

1

2

4

3

9

READY

>

ONERR

Purpose

Use the ONERR statement to handle arithmetic errors, if they occur, during
program execution. Only arithmetic overflow, arithmetic underflow, divide by zero,
and bad argument errors are trapped by the ONERR statement. All other errors are
not trapped and cause the module to enter the Command mode. If an arithmetic
error occurs after the ONERR statement is executed, 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 8-5.

After the ONERR statement is executed, 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 = 20-ARITH. OVERFLOW or ARITH.UNDERFLOW

ERROR CODE = 40-BAD ARGUMENT

You can examine this location by using an XBY(257) statement.

Syntax

ONERR [ln num]

Advertising