Get(LastError)

Category: Get

Syntax: Get ( LastError )

Parameters: None

Data type returned: Number

Description:

Returns the number of the error generated by the most recent script step. If there was no error, then Get (LastError) returns 0. Use this function in combination with Set Error Capture [On] to trap and handle errors raised in scripts.

A common source of bugs in scripts is not remembering that the Get (LastError) function returns the error code from only the most recently executed script step. For example, in this script

Perform Find If (Get(ErrorCaptureState) = 1) Show Custom Dialog (Get (LastError)) End If

the Get (LastError) step returns the result of the execution of the If statement, not the error code generated by the Find step.

Note that if a script is running on the Mac OS and calls an AppleScript routine, any errors generated will also be passed through to and presented via this function.

Note too that if an error occurs in FileMaker while performing an SQL query, an SQLSTATE error will be returned by ODBC.

Examples:

Consider the following script:

Set Error Capture [On] Print Setup[Restore] SetVariable [$error; value: Get (LastError)]

If the user cancels out of the Print Setup dialog, Get (LastError) returns 1 (user canceled action). If the Print Setup step executes successfully, Get (LastError) returns 0.

Категории