Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

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 %StatusOpens in a new window data type. For example, the %Save method, used to save an instance of %PersistentOpens in a new window object to the database, returns a %StatusOpens in a new window value indicating whether or not the object was saved.

With Caché Basic you can use the System.Status object to inspect and manipulate %StatusOpens in a new window 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.StatusOpens in a new window class.

FeedbackOpens in a new window