|
Exceptions
|
|
An exception is a runtime error, and you can determine whether a runtime error should cause a pause when debugging, like a breakpoint.
Distinguish between a handled runtime error and an unhandled runtime error. A handled runtime error is an error that occurs within a try block. It would not normally cause any break in the action, because AppleScript will just call the on error clause if there is one, or just abandon the try block and continue execution after the block. An unhandled runtime error, on the other hand, causes execution to abort entirely, so there is no issue about pausing there — the script will do more than pause, it will stop.
To pause at handled runtime errors:
- Choose Script > Break on Exceptions. If the menu item is checked, we will pause handled runtime errors. Alternatively, there is also an optional toolbar icon you can add to the script window toolbar; the icon toggles its state to show whether we’re going to break on exceptions or not.
If Break on Exceptions is checked, a handled runtime error causes a pause when encountered in debug mode. Execution pauses at the line where the runtime error was encountered, before the error is thrown, and variables and expressions are evaluated at that point.
To learn what the error was:
- Look at the bottom of the result pane. The error message is displayed there.
- Choose Script > Show Last Error, or click the red arrow at the point where the error occurred. This summons the normal error dialog. (You can also add a Show Last Error button to the script window’s toolbar.)
If Break on Exceptions is unchecked, then a handled runtime error does not cause any pause. However, you can still learn, during any pause after the error is encountered (but before some other runtime error is encountered), where the error was, by choosing Search > Go to Last Error, and what the error was, by choosing Script > Show Last Error.