Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section

Error Handling

This chapter describes the mechanisms Caché Basic provides for handling application errors.

On Error Goto

The On Error Goto statement lets you define an action to take should a runtime error occur:

On Error Goto MyError
x = 1 / 0 'induce an error

PrintLn "We will never get here..."
' ...

    PrintLn "Error: " & Err.Description
Copy code to clipboard

When a runtime error occurs, execution will jump to the local label specified by the On Error Goto statement. The Err object (see below) will contain information about the error.

The Err Object

The Err object is a built-in object that contains information about the current error. Typically you use this within an On Error handler.

For more information refer to the Err Object reference page.

The System.Status Object

Many of the methods in the Caché class library return success or failure information via the %Status data type. For example, the %Save method, used to save an instance of %Persistent object to the database, returns a %Status value indicating whether or not the object was saved.

With Caché Basic you can use the System.Status object to inspect and manipulate %Status values.

For example, the following code tries to save an object that has missing required values:

person = New Sample.Person()
person.Name = "Nobody"
person.SSN  = "" ' required!

' Save this object
status = person.%Save()

If (System.Status.IsError(status)) Then
End If
Copy code to clipboard

For more information, refer to the System Object reference page as well as the %SYSTEM.Status class.