Java Reference
In-Depth Information
Some errors are not necessarily bugs in your code, but in fact exceptions to the normal
circumstances that cause your code to fail. You saw that the try...catch statements are
good for dealing with this sort of error, and that you can use the catch clause with the
throw statement to deal with likely errors, such as those caused by user input. Finally, you
saw that if you want a block of code to execute regardless of any error, you can use the
finally clause.
You looked at the debugging tools found in Chrome (and by extension Opera), Internet
Explorer, Firebug for Firefox, and Safari. With these tools you can analyze code as
it executes, which enables you to see its flow step by step, and to check variables and
conditions. And although these debuggers have different interfaces, their principles are
identical.
exerCises
You can find suggested solutions to these questions in Appendix A.
1. The example ch18_example4.html has a deliberate bug. For each times table it creates only
multipliers with values from 1 to 11 .
Use the script debugger to work out why this is happening, and then correct the bug.
2. The following code contains a number of common errors. See if you can spot them:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 18: Question 2</title>
</head>
<body>
<form name="form1" action="">
<input type="text" id="text1" name="text1" />
<br />
CheckBox 1<input type="checkbox" id="checkbox2" name="checkbox2" />
<br />
CheckBox 1<input type="checkbox" id="checkbox1" name="checkbox1" />
<br />
<input type="text" id="text2" name="text2" />
<p>
<input type="submit" value="Submit" id="submit1" name="submit1" />
</p>
</form>
<script>
function checkForm(e) {
var elementCount = 0;
var theForm = document.form1;
while(elementCount =<= theForm.length) {
 
Search WWH ::




Custom Search