Some statements in EASI allow the programmer to trap errors through the use of the ONERROR statement suffix. The general form for statements which accept the ONERROR suffix is:
[statement1] ONERROR [statement2]
where
statement1 is a statement that supports the ONERROR suffix.
Statement2 is any valid EASI statement to be executed only if
an error occurs while executing statement1.
For example, if x=0 in the Invert() function presented above, using the ONERROR form of the assignment (LET statement) provides a way for execution to continue:
y = 1 / x ONERROR y = 0 y = 1 / x ONERROR goto ErrorHandler y = 1 / x ONERROR error = GetLastErrorNumber()
In the first case shown above, the variable y will be assigned the value 0 if an error occurs. Note that this will occur regardless of what error actually occurred. That is, if the user called invert with a string instead of a numeric argument, a different error would occur represented by a different error code, but the error will be handled in the same way by executing the ONERROR statement.
In the second case, control will transfer to the point marked by the label ErrorHandler. The function Invert() should define this the label followed by appropriate code to execute if an error occurs, for example:
define function Invert( x )
local integer y
y = 1 / x ONERROR goto ErrorHandler
return( y )
ErrorHandler: \
print "An error occurred while executing Invert(", x, ")"
return ( 0 )
enddefine
Finally, in the last case the variable error will be assigned the error code which is obtained using the GetLastErrorNumber() intrinsic function. This error code can then be examined by subsequent code to determine a course of action.
define function Invert( x )
local integer y, error
error = 0
y = 1 / x ONERROR error = GetLastErrorNumber()
if ( error = 0 ) then
return( y )
else
print "An error has occurred"
return( 0 )
endif
enddefine
In the above example, the code prints a message and returns zero if any error has occurred.
The NOERROR keyword can be used to completely suppress errors in the supported statements.
y = 1 / x NOERROR
In this case, if any error occurs it is ignored, and execution continues with the next statement. No assignment will occur, and the variable y will contain the value it had before the assignment statement causing the error was executed. A more common example is to delete a file if it exists, and continue executing even if the deletion failed (as when the file doesn't exist):
DELETE "tmpfile.pix" NOERROR
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.