Skip to main content

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

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 tab data type. For example, the %Save method, used to save an instance of %PersistentOpens in a new tab object to the database, returns a %StatusOpens in a new tab 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 tab 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

For more information, refer to the System Object reference page as well as the %SYSTEM.StatusOpens in a new tab class.

FeedbackOpens in a new tab