Intranet Journal Intranet FAQ

IDM Intranet FAQ          [Previous | Index | Next]

JavaScript FAQ

Answers to Questions about...
Troubleshooting JavaScript/JScript

2. Where can scripts go wrong?

There are three distinct areas where errors can occur in any computer program:

  • Load-time errors
  • Run-time errors
  • Logic errors

Load-time errors
Your script is part of a web page. When someone browses (i.e., requests) that page, your server returns it over the network. On receiving it the requesting browser loads your page: HTML, JavaScript, and any other objects it contains.

Load-time errors are caught by the JavaScript interpreter. As the browser loads your script, it performs myriad checks for basic language problems -- usually syntax errors. If, for instance, you leave off the closing half of a pair of parentheses, the interpreter will tell you about it in the form of a load-time error. Why? Because a script can't run until it has loaded successfully.

By checking your scripts in two browsers -- Netscape Navigator 3.0 (or later) and Microsoft Internet Explorer 3.0 (or later) -- you leverage the language-checking abilities of JavaScript itself to detect load-time errors.

Run-time errors
If your script loads, it will run. It may perform exactly as you designed it to, or it may crash and burn. Like load-time errors, problems at run-time are detected and reported by the JavaScript interpreter. In effect, it says (very quietly): "I loaded that nice-loking script and now it's breaking the rules, corrupting memory and whatnot. I'd better tell somebody." Up pops an alert window to apprise you of the run-time error.

When a program is running it manipulates stored data, operating on values in memory as specified by program commands. Thus, whereas errors occur at load time chiefly due to bad syntax, run-time errors are often due to misuse of the language's commands.

For instance, you'll get a run-time error if at some point your script divides by zero (illegal in any language).

Logic errors
These are the bad guys, problems worthy of the epithet "bugs." Errors loading or running your script are caught by the machine; errors in the logic of you program can only be caught by you or your users -- in other words, humans. When your script runs without complaining but ends up doing the wrong thing, you've got a logic error.

The best way to verify your program logically is to stress it. You probably won't be able to exercise all the possible inputs, outputs, if-then statements and loops, but by hitting a few major ones, you gain confidence that any errors are at least well hidden. If and when these occur, of course, they may be equally hard to trace. But that's software for you.

 

IDM Intranet FAQ          [Previous | Index | Next]