|
|
|

|
Pause
|
|
The difference between debug mode and normal mode is that in debug mode your script can pause while executing. The key to debug mode’s behavior is the relationship between the various things that can cause your script to pause.
When a script is paused:
- The Execute command becomes the Resume command. The name changes in the Script menu and in the toolbar.
- In the Script menu, the Pause menu item is changed to Paused and is checked.
- In the toolbar and the Script menu, the step commands (and Stop) are enabled.
- In the Window menu (and the Windows Inspector), the listing for this script window is badged with an icon indicating that it is paused.
- The all-important blue arrow in the gutter indicates the line at which your script is paused; this line has not yet been executed.
Visualize what happens when your script runs. One line is executed, then another, then another. There are branches, so some code might not be executed. There are loops and handlers, so some code might be executed several times. Like a mouse running in a maze, the computer traces a path of execution through your code. (You can actually watch this happening in debug mode, by tracing.)
A breakpoint is a line where, if the path of execution comes to it, execution will automatically pause. It pauses before executing the breakpointed line. Breakpoints take priority over everything. When you are in debug mode, no matter how you cause execution to proceed, the script will pause when the path of execution hits a breakpoint (unless you have unchecked Script > Break on Breakpoints).
The step commands cause execution to proceed by a limited amount. A step command means, “Start or resume executing, and pause when you come to a certain thing,” where each step command has a different idea of what that certain thing is. But remember, breakpoints take priority. If the path of execution hits a breakpoint before hitting the thing the step command is looking for, execution will pause (unless you have unchecked Script > Break on Breakpoints).
If you’ve elected to break on exceptions, encountering a runtime error (even an error that your script catches and handles) will pause your script.
During a lengthy bout of execution, you can manually pause the script by choosing Script > Pause (or use the Pause button on the toolbar).
Distinguish stopping from pausing!
- The Pause button, and all the other ways of pausing, leave you somewhere in the middle of execution. From here, you can proceed further, even completing the script normally if you want to.
- The Stop button (or choosing Script > Stop) aborts execution right where it is and returns everything to a completely neutral state. If you execute the script now, you’ll be starting at the very beginning once more.
While you are paused, you can examine the state of your script. You can view the call stack, the values of your variables, the values of expressions, and the Apple Event Log window.
Then you can make your script proceed once again.
Tip: If your script is paused but you don’t know where (because you’ve scrolled to examine some other region of the script), choose Search > Go to Current Line to bring the line containing the blue arrow into view.
Explore | Edit |
Run & Debug | Deploy | What's New In 4.5 |
My SD Story
|