# onerr clause

The onerr clause identifies the statements
to execute when an error occurs during statements that perform operations
on peripheral storage devices.

## Syntax

```
onerr statement.block
```

## Description

The system(0) function contains the error message associated with the onerr condition.

The onerr clause
is used in the same construct as the then/else construct.

Either an onerr clause or an else clause is allowed
in a statement, but not both. They are similar, in that they are taken
when the peripheral operation takes a decision-point or failure path.
The onerr form provides a great deal more functionality,
but at a higher cost. When the onerr clause exists,
all media handling must be handled by the program. This means, for
example, that the program is responsible for handling an end of reel
condition. Thus the program would have to prompt the operator for
the next reel. By contrast, the else clause would
handle the same situation by passing through the standard system routine
to:

```
Mount next reel and press c to continue.
```

## Example(s)

In this example, the onerr path is taken in the event of any abnormal condition,
and it displays the value of system(0).

```
readt tape.rec onerr
 crt "oops. we&#39;ve got a system(0) error of " : system(0)
end
```
This example illustrates how processing for an error could
be divided out based upon the error that occurred.

```
readt tape.rec onerr
 condition = system(0)
 begin case
 case condition = 1
 print "tape is NOT attached..."
 case condition = 5
 print "process end of reel"
 case condition = 6
 print "tape is write-protected"
 end case
end
```

## See also

- [else clause](https://d3codex.com/pickbasic-flashbasic/else-clause/)
- [readt statement](https://d3codex.com/pickbasic-flashbasic/readt-statement/)
- [readtx statement](https://d3codex.com/pickbasic-flashbasic/readtx-statement/)
- [rewind statement](https://d3codex.com/pickbasic-flashbasic/rewind-statement/)
- [statement blocks](https://d3codex.com/pickbasic-flashbasic/statement-blocks/)
- [system() function](https://d3codex.com/pickbasic-flashbasic/system-function/)
- [t-att command](https://d3codex.com/tcl/t-att-command/)
- [then clause](https://d3codex.com/pickbasic-flashbasic/then-clause/)
- [then/else statement blocks](https://d3codex.com/pickbasic-flashbasic/then-else-statement-blocks/)
- [weof statement](https://d3codex.com/pickbasic-flashbasic/weof-statement/)
- [writet statement](https://d3codex.com/pickbasic-flashbasic/writet-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/onerr-clause/ - part of the D3Codex reference.
