Error recovery patterns: the FileMaker Try-Catch equivalent

Expert

Implement structured error recovery in FileMaker scripts using OnError labels, error translation tables, and cleanup routines that mirror try-catch patterns.

What you'll learn

  • How to implement the try-catch pattern with OnError labels
  • How to build an error translation table for common FileMaker error codes
  • How to implement a finally block equivalent for cleanup that always runs
  • How to propagate errors through multiple levels of script calls
  • How to distinguish retryable errors from fatal ones

FileMaker has no native try-catch syntax, but the combination of OnError [ Go to [label] ], Set Error Capture [ On ], and a cleanup label creates an equivalent pattern. When implemented consistently, this gives every script a predictable error surface: errors jump to a known handler, get translated into human-readable messages, trigger cleanup, and exit with a structured result the caller can inspect.

1/3
1

The standard try-catch script skeleton

Every script that touches data should follow this skeleton: Set Error Capture On, OnError to the error label, main logic, Exit Script with success, then an error label that captures the code, translates it, runs cleanup, and exits with a failure result.

FileMaker Script
# Script: Invoice - Commit
Set Error Capture [ On ]
OnError [ Go to [::HandleError] ]

# -- TRY BLOCK ------------------------------
Commit Records/Requests [ Skip data entry validation: Off ; No dialog: On ]
# If this step fails, FileMaker jumps to ::HandleError

Exit Script [ Text Result:
  JSONSetElement ( "{}" ; [ "success" ; True ; JSONBoolean ] )
]

# -- CATCH BLOCK ----------------------------
::HandleError
Set Variable [ $code ; Value: Get ( LastError ) ]
Set Variable [ $message ; Value:
  Case (
    $code = 301 ; "This record is locked by another user. Please try again in a moment." ;
    $code = 500 ; "A required field is empty. Please complete all required fields." ;
    $code = 301 ; "Record is currently in use." ;
    "An unexpected error occurred (code " & $code & ")."
  )
]
# -- FINALLY BLOCK (cleanup) ----------------
Allow User Abort [ On ]
# -- EXIT WITH ERROR ------------------------
Exit Script [ Text Result:
  JSONSetElement ( "{}" ;
    [ "success" ; False ; JSONBoolean ] ;
    [ "error" ; $message ; JSONString ] ;
    [ "code" ; $code ; JSONNumber ]
  )
]

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo