Java Reference
In-Depth Information
The finally part is a good place to put any cleanup code that needs to execute regardless of any
exceptions that previously occurred.
You've seen the top mistakes made by developers, and you've also seen how to handle errors in your
code. Unfortunately, errors will still occur in your code, so let's take a look at one way to make
remedying them easier by using a debugger.
deBugging
JavaScript is traditionally looked upon as a difficult language to write and debug due to the lack of
decent development tools. This, however, is no longer the case thanks to the tools made available
through the browser: the debugging tools available for Internet Explorer, Firefox, Chrome, and
Opera. With these tools, you can halt the execution of your script with breakpoints and then step
through code line by line to see exactly what is happening.
You can also find out what data is being held in variables and execute statements on the fly. Without
debuggers, the best you can do is use the alert() method in your code to show the state of variables
at various points.
Debugging is generally universal across all browsers, and even languages. Some debugging tools
may offer more features than others, but for the most part, the following concepts apply to any
debugger:
Breakpoints tell the debugger it should break, or pause code execution, at a certain point.
You can set a breakpoint anywhere in your JavaScript code, and the debugger will halt code
execution when it reaches the breakpoint.
Watches enable you to specify variables that you want to inspect when your code pauses at a
breakpoint.
The call stack is a record of what functions and methods have been executed to the
breakpoint.
The console enables you to execute JavaScript commands in the context of the page and
within the scope of the breakpoint. In addition, it catalogs all JavaScript errors found in the
page.
Stepping is the most common procedure in debugging. It enables you to execute one line of
code at a time. You can step through code in three ways:
Step Into executes the next line of code. If that line is a function call, the debugger
executes the function and halts at the first line of the function.
Step Over, like Step Into, executes the next line of code. If that line is a function,
Step Over executes the entire function and halts at the first line outside the
function.
Step Out returns to the calling function when you are inside a called function. Step
Out resumes the execution of code until the function returns. It then breaks at the
return point of the function.
 
Search WWH ::




Custom Search