Part II: Applying Your Skills - The Center Park School Project


Understanding Error Messages

Now that you know how to display error messages, you're probably wondering what the message means. People in the computer industry used to joke about error messages because these messages were generally (and sometimes still are) short, confusing, and oftentimes of no use whatsoever. It would not be uncommon for an early program writer to get an error similar to "Error #3810482," which contains no useful error message at all. Error messages have become more sophisticated and useful since they first began appearing, but they can still sometimes be quite confusing.

JavaScript error messages generally have three parts to them. If you look at Figures 13.2 and 13.5, you will notice that the figures both show the name of the file that caused the error, C:\JPP\Error.html; the line on which the error was detected, 22; and the actual error message,

myObject is not defined.

The first part of every error message, the path to the file that caused the error, is useful only if you are using a multiple-page Web site. If you're building a site that has multiple frames or that shares functions between pages, this error information will narrow your search for the cause of the error down to one page.

The second part of every error message is the line number on which the error was detected. Unfortunately, there is a big difference between which line caused the error and in which line the error was detected. In the running example so far, the line number is helpful because line 22 was the line in which I used an object instance myObject before the variable was actualy defined. This is not always the case. One notable exception of an error message giving the wrong line number is when you forget to end a string literal with a quotation mark. The interpreter will not normally catch the error on the line that is missing a quotation—it will catch it in the next <script> block of the Web page. As a rule of thumb, the error in question usually occurred on the line number that was given in the error message or shortly before it.

The last part of every error is a message defining the type of error that occurred. This part of the error message is usually self-explanatory, but it can occasionally be confusing if you aren't familiar with every aspect of the JavaScript language. If the message is helpful, then great, go fix the error. If the message is confusing, don't worry about it—the first two parts of the error message will usually provide enough information to fix the error.

Debugging is not an easy task. Nobody writes a program perfectly the first time through, which makes debugging a useful and necessary skill to acquire.

If you encounter an error that you are having difficulty fixing, try these simple steps to get you started:

  • Fix only one error at a time. Oftentimes, several errors will be caused by a single error previously in the document. Fixing the first error first will usually solve the following ones.

  • Seek help. Chances are that others in your field have already encountered the error you're working on. If so, they will generally be more than willing to help you solve the problem. If you're working on a project alone, use the Internet to find help with the problem. Searching for a specific error message on the Internet usually provides a large number of possible solutions on discussion boards and online databases.

  • Be patient. Some errors just take time to figure out. If you find a particularly difficult bug and have worked on it for a long time to no avail, leave it for later. You can always work on a different part of your project or take a break. A fresh perspective may be all that is required.




JavaScript Professional Projects
JavaScript Professional Projects
ISBN: 1592000134
EAN: 2147483647
Year: 2002
Pages: 130
Authors: Paul Hatcher

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net