JavaScript
  Home arrow JavaScript arrow JavaScript Errors
FaxWave - Free Trial.
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript Errors
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2008-01-07

    Table of Contents:
  • JavaScript Errors
  • Try...Catch
  • Throwing the Ball (and Exceptions)
  • By the Numbers

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    JavaScript Errors
    (Page 1 of 4 )

    When last we spoke, we discussed the various Events in JavaScript. In this tutorial we will go over some of the errors that can occur and how to deal with them. I know, I know: how can any of your programs possibly fail when you have been taught by the JavaScript Ninja? Well, you can blame that on the good folks that create the various browsers.

    Old Schooling it with the OnError Event

    I believe we covered this briefly in our last series, but we will do so a little more in depth here. The OnError event occurs whenever there is a script error on the page. To use the event, you create a function to deal with the error. When the error occurs, the function is called by the Onerror event handler, which consists of three arguments: the error message (msg), the URL of the page where the error occurred (url), and the line where the error occurred (line). Here it is in code:


    <html>

    <head>

    <script type="text/javascript">

    onerror=handletheerror

    var txt=""


    function handletheerror(msg,url,l)

    {

    txt="An error has occurred.nn"

    txt+="Error: " + msg + "n"

    txt+="URL: " + url + "n"

    txt+="Line: " + l + "nn"

    txt+="Click OK to continue.nn"

    alert(txt)

    return true

    }


    function message()

    {

    adddblerto("Greetings!")

    }

    </script>

    </head>


    <body>

    <input type="button" value="Click to trigger the error" onclick="message()" />

    </body>


    </html>

    In the code above, we create a function named handletheerror that will occur when the Message function fails to work (note that this function fails to work because the adddblerto should actually be code for an alert, but has many typos; if you fixed the code, the onerror event would never occur). It triggers a pop-up box that tells you an error has occurred, the URL at which it occurred, and on which line in the code the error appears.

    Note that when counting lines, JavaScript includes blank lines as well.

    More JavaScript Articles
    More By James Payne


       · Thanks for stopping by to read my article on JavaScript errors. In this issue we...
     

    JAVASCRIPT ARTICLES

    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps
    - Adding Zoom Controls to Yahoo! Maps
    - Working with Yahoo! Maps
    - Building Image Zooming Controls with the DOM...
    - Working with Multiple Graphics for a Zoom Ap...
    - Improving an Image Zooming Application with ...
    - Zooming in on Images with JavaScript
    - JavaScript Date Objects: Universal Coordinat...
    - Javascript Objects: More Date Methods
    - JavaScript Objects: Dates
    - JavaScript Objects: Finishing Strings

    Iron Speed

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway