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:
on error(local-name)
[label: ] statement [; ...] ...
end
| Element... | Meaning... |
|---|---|
local-name
|
A local name whose type is class error or any subclass of error.
|
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.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:
begin
statement [; ...]
end
on error (symbolic-local-name, text-local-name)
[statement [; ...] ]
end
|
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.
|
sample-proc()
error-name: symbol;
error-text: text;
begin
inform the operator that
"This is a sample statement within a begin-end block";
call proc-with-signal();
end
on error (error-name, error-text)
inform the operator that
"An [error-name] error occurred. [error-text]";
end
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.