JavaScript
  Home arrow JavaScript arrow Exception Handling in JavaScript: Introduc...
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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

Exception Handling in JavaScript: Introduction to Core Concepts
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2005-09-07

    Table of Contents:
  • Exception Handling in JavaScript: Introduction to Core Concepts
  • Exceptional code: introducing the basics of JavaScript exceptions
  • Trapping exceptions: explaining “try-catch” blocks
  • A basic example: handling exceptions through a generic mechanism

  • 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
     
     
    ADVERTISEMENT


    Exception Handling in JavaScript: Introduction to Core Concepts


    (Page 1 of 4 )

    JavaScript 1.5 remedied an omission of earlier versions by including built-in support for advanced exception handling. Of course, just because the support is there doesn't mean that developers will enjoy error-free code! For this reason, JavaScript exceptions should be properly considered when writing applications. This article is intended to provide you with the basics about exceptions.

    For most programmers accustomed to working with a thoroughly object-oriented language like Java, exceptions are long-established programming structures that allow them to handle multiple runtime errors through a centralized mechanism within client code. Certainly, this method for handling errors has proven to be highly successful in the vast majority of applications, which turned it rapidly into the standard technique for delegating error manipulation to specific fragments of code, different from those that generate error conditions.

    Particularly, JavaScript was one of the client-side scripting languages that wasn’t “blessed” with a powerful built-in exception mechanism, so for most developers, tracking script errors was for a long time an experience tightly tied to including alerts inside the code or settling down with browser-based error debuggers, such as the popular “JavaScript console.” Although all these tools together have significantly simplified error tracking and debugging, still JavaScript programs lacked true support for exceptions.

    With the release of JavaScript 1.5 (available from most sixth generation browsers onward), built-in support for advanced exception handling is available to all developers, allowing them to write more robust code by using popular “try-catch” blocks, as well as working with “throw” statements for complex user-defined exceptions.

    Of course, wrapping up all the code into “try-catch” blocks doesn’t make sure that JavaScript programs will be error-free at all, but it does implement a strong mechanism for solving errors within the application layer, all without messing up the code with old-fashioned error checking routines.

    It’s precisely for that reason that JavaScript exceptions should be properly considered when writing applications, according to the tendencies that modern Web programming dictates. Considering this scenario, this article is intended mainly to provide you with the basics about exceptions, by explaining its benefits and exploring its implementation.

    Also, the series will cover the most common error types found during program execution, in conjunction with some JavaScript constructs useful for solving them gracefully. Since only theoretical concepts are rather useless on their own, numerous examples will be explained, so you can start using exceptions in your JavaScript programs.

    More JavaScript Articles
    More By Alejandro Gervasio


       · The first part of the series goes through the explanation of basics exception...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT