Xbasic

ON ERROR GOTO, RESUME NEXT

Syntax

ON ERROR RESUME NEXT

ON ERROR RESUME LabelName

ON ERROR RESUME 0

ON ERROR GOTO NEXT

ON ERROR GOTO LabelName

ON ERROR GOTO 0

Arguments

ON ERROR GOTO 0

Disables error handling.

ON ERROR GOTO LabelName

Branch to the address of LabelName (expecting it to be an error handler). The label name cannot contain spaces.

ON ERROR GOTO NEXT

Branch to the next line (expecting it to be an error handler).

ON ERROR RESUME 0

Disables error handling.

ON ERROR RESUME LabelName

Ignore the error and branch to the address of LabelName. The label name cannot contain spaces.

ON ERROR RESUME NEXT

Ignore the error and go to the next instruction.

Description

Expects to have the error handled

Discussion

Note that the ON ERROR GOTO statement expects to have the error handled, while ON ERROR RESUME expects to have the error ignored. When using ON ERROR RESUME NEXT, there will not be error information available after the branch. ON ERROR RESUME NEXT may produce an error if there is no NEXT to resume to. See Also, ERROR_GENERATE(), ERROR_CODE_GET(), and ERROR_TEXT_GET().

Examples 

For example, the following script shows a generic error handling routine:

on error goto error_handler
'put Xbasic code here
end
error_handler:
    err = error_code_get()
    msg = error_text_get(err)
    ui_msg_box("Error", msg)
end

When an error is encountered, this routine displays the text message from the error and then ends script execution. For more robust error handling, use the ERROR_CODE_GET() function to determine exactly which error occurred. You can then take steps to recover from this error so you can resume script execution.

Each function should handle and clear its own errors. A calling function will see errors created within called functions, but will not be able to properly handle RESUME statements.

This error handling routine is evaluated when x = 3. The ERROR_GENERATE() function is used to generate the run-time error. The TRACE object is used to log messages to the Trace Log.

trace.writeln("Start")
on error goto error_handler
for x = 1 TO 10
    if (x = 3) then
        ERROR_GENERATE()
    end if
    trace.writeln( str(x) )
next x
trace.writeln("End")
end
error_handler:
    trace.writeln("Error processed.")
    resume next

This script shows how an error handler is used to recover from a field rule violation.

tbl = table.current()
if (tbl.mode_get()> 0) then
    'Compute the Message Type code
    code = UI_ATTENTION_SYMBOL
    ui_msg_box("Warning", "Already in data entry mode.", code)
else
    commit_flag = .T.
    tbl.change_begin()
    on error goto error_handler
    tbl.last_name = "Washington"
    tbl.first_name = "George"
    tbl.change_end(commit_flag)
end if
parent.resynch()
end
error_handler:
    commit_flag = .F.
    resume next

See Also