Structured error trapping with OnError
ExpertBuild bulletproof scripts by combining OnError [ Go to [label] ] with Get(LastError) lookup tables.
What you'll learn
- How to redirect script flow on error using labels
- How to capture and translate error codes with Get(LastError)
- How to clean up partial changes before exiting on error
The default OnError [ Stop ] behavior halts a script and shows the user a raw error dialog. Switching to OnError [ Go to [label] ] lets you capture the error code, translate it into plain language, clean up any half-completed work, and exit gracefully.
1/3
1
Redirect errors to a handler label
Place OnError [ Go to [label] ] at the top of your script. Add a label like "::Error" near the bottom. FileMaker jumps to that label whenever a script step returns a non-zero error code.
FileMaker Script
# Top of script Set Error Capture [ On ] OnError [ Go to [::Error] ] # ... main script logic ... Exit Script [ Text Result: "success" ] ::Error Set Variable [ $errorCode ; Value: Get ( LastError ) ] Show Custom Dialog [ "Operation failed (code " & $errorCode & ")" ] Exit Script [ Text Result: "error" ]
Sign in to track your progress and pick up where you left off.
Sign in to FM Dojo