Benches macOS

2

applescript and error handling

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hi,

is there something like error-handling for applescript in general or just limited to special actions/functions like "try" ?

i want to optimize my applescript app just for the case that it could be needed.

Best regards

fidel

2 replies

Sign in or join Beachball Help to reply.

  1. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    It's not clear quite what you're asking for.

    Try/end try blocks are the basis of error trapping - allowing your application to fail gracefully and execute a specific block of code should an error occur. It is not clear what more you're looking for.

  2. 0

    R C-R

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    To elaborate a bit, error handling in a 'try' block is implemented with the 'on error' statement. The simplest use is something like this pseudo-script :

    try

    {script steps that might produce an error}

    on error

    {script steps for the error condition}

    end try

    'on error' optionally will return information about the error. Most widely used are the error message (text) & the error number:

    try

    {script steps that might produce an error}

    on error errMsg number errNum

    {script steps for the error condition using the variables errMsg and/or errNum}

    end try

    The second form allows you to detect & handle specific errors.