|
Errors
|
|
AppleScript generates two kinds of error — compile errors and runtime errors — and Script Debugger provides full information about where the error occurred and what went wrong.
Script Debugger presents error information in a dialog. When you dismiss the dialog, you’ll find that your script has been clearly marked with the location of the error, in three ways:
- A little “stop sign” icon (
) for a compile error, or “red arrow” icon (
) for a runtime error, appears in the gutter next to the problematic line.
- The line itself is highlighted, and the troublesome words are selected.
- A little red mark appears in the scroll bar.
To show the error message again after dismissing it:
- Choose Script > Show Last Error, or click on the “stop sign” icon (
) or “red arrow” icon (
) in the gutter. Alternatively, hover the mouse over the stop sign or red arrow, to see the text of the error message in a tooltip. (You can also add a Show Last Error button to the script window’s toolbar.)
To scroll to where the problem is:
- Use the red mark in the scroll bar as a guide, or choose Edit > Go To Last Error (this immediately scrolls the window to bring the problematic line into view).
Compile Error
A compile error is reported as a text message from AppleScript. Script Debugger displays this text as a dialog.
Runtime Error
A runtime error can result in a more elaborate message from AppleScript. Therefore, the error dialog is more elaborate as well.
The message can contain up to six parts. Five of these correspond to the five parameters of the AppleScript error command, plus there is an Application parameter supplied by AppleScript. In the dialog, Script Debugger presents up to five of these parts of the message as individual panes, which you access through the buttons at the top of the dialog. The sixth part, the error number, is shown at the lower left of the dialog. Here is the correspondence between error command parameters and how they are shown in the dialog:
- message string
- Shown as the Message pane.
- number
- Shown at the lower left of the dialog.
- partial result
- Shown as the Partial Result pane.
- from
- Shown as the Offending Object pane.
- to
- Shown as the Expected Type pane.
- [application]
- Shown as the Application pane.
A pane of the error dialog might consist of a viewer. If the value shown is an object reference, Best view is an explorer view, and individual lines can be double-clicked to create a separate viewer window.
If your script catches (handles) a runtime error with a try block, the error does not percolate up to AppleScript and it is not reported back to Script Debugger. In effect, there is no error. In debug mode, however, you can break on an error even if it is caught.
For information about a special kind of error situation where a file or transaction is left open, read on.