The Ugly JavaScript Book - Chapter Twelve

Chapter Twelve
Error Messages


Trying to interpret those Error Messages that appear when things go wrong is becoming easier as the Browsers are improved.
     Note to revised version:
     Newer versions of the Netscape® Browser have a special JavaScript console which must be invoked to display error messages. If your script fails to work, but no error message appears, type "javascript:" on the location line and then hit the return key to open the console window.
     If you are using the Microsoft® Internet Explorer, be sure that error display is enabled in the Preferences. To find the error in the source code, you then click the "Source" button to see the errant code highlighted in the source.
     If the display highlights the top line of the HTML, you will know that you have forgotten to tag out the script or have made an error with the comments in the script.

     It happens all the time, unfortunately, unless you are one of those folks who are perfect...
     An impudent dialog box appears, covering half the screen, informing you that you've screwed up.
     Some of these are pretty easy to understand and are a real help in figuring out what you did wrong.
     For example, if the message has something to do with "unterminated string", you can figure that you screwed up your double and single quotes in a string, or you forgot that you can't make a code line more than 50 or 60 characters long.
     Many times the error message will give a JavaScript line number. However, this line number is at best an indicator pointing you close to where the problem occurred, since the compiler line counter generally will bear little resemblance to the way you have written your script.
     So if it says there's an error on line 65, you will want to start looking at about line 50 for the error.
     There are other error messages that may point you to where the error is occurring by the way they are worded.
     For example, if the message is "Window.document searcher.text has no properties", you can be pretty sure that either the form named "searcher" wasn't found with an element named "text" in it or you gave it the wrong frame pane to look in, or the form wasn't yet loaded before it looked for it.
     You may be saying to yourself about now, "Well, what good is the error message?" First, it tells you that you have a problem, and second, it helps you narrow down what the problem is, most of the time. That's helpful. Really...

Links: Introduction | Chapter One | Chapter Two | Chapter Three | Chapter Four | Chapter Five | Chapter Six | Chapter Seven | Chapter Eight | Chapter Nine | Chapter Ten | Chapter Eleven | Chapter Thirteen | Chapter Fourteen | Chapter Fifteen | Chapter Sixteen | Chapter Seventeen | Chapter Eighteen | Chapter Nineteen | Chapter Twenty | Chapter Twenty-one | Chapter Twenty-two | Chapter Twenty-three | Appendix A | Appendix B | Appendix C | Appendix D | Cover
This free virtual book provided courtesy of:
AutoScripter(tm), the site for professional Web Designers and Developers and
WebWalker Virtual Press, virtual publishing on the Web since 1994
Other free e-books from WebWalker: The All American Terrorists | The Gnomes of Jost | For the Love of Entropy | The Trees of Kratva | The Arch of Rain Magicians | Lightshow | The Black Mancutters Guild | The Septoracle

© Copyright 1997, 1999, 2000, 2001 John H. Keyes
editor@jorika.com