| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (21 out of 25)

on error

G2 provides error handlers. The default error handler prints a message to the logbook describing the error. You can use the on error statement to define an error handler that is specific to any begin-end block in a procedure, including the outer block that contains all of the executable code.

For complete information on G2 error handling, see Chapter 41, Error Handling. For information about the signal statement, see signal.

G2's default error handling capabilities are synchronous: they do not enter a wait state during handling of an error. This protects the context within which the error occurred from asynchronous changes. User-defined error handling capabilities can allow other processing if appropriate. For information on wait states, see Allowing Other Processing.

On Error Statement Syntax

The syntax of the on error statement is:

An on error statement appears immediately after the end statement of the block to which it applies. For example:


An on error statement executes if and only if G2 signals an error within the scope of the statement, or a signal statement executes within the scope of the statement. Otherwise, control skips over the on error block and continues sequentially.

For complete information about the on error statement, see Defining an Error Handler.

Superseded On Error Statement Syntax

For compatibility with earlier versions of G2, the on error statement also accepts two arguments. The syntax is:

where:


A local name that contains a symbol. You must declare this name locally in your procedure.

A local name that contains text. You must declare this name locally in your procedure.

For example:

The two-argument form of the on error statement should not be used in new code. A KB can mix both forms of the statement, and can use either form in conjunction with either form of the signal statement. G2 automatically interconverts between the two syntaxes, as described under Mixing Error Handling Techniques.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (21 out of 25)

Copyright © 1997 Gensym Corporation, Inc.