Home arrow JavaScript arrow Exception Handling in JavaScript: Introduction to Core Concepts

Exception Handling in JavaScript: Introduction to Core Concepts

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.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 11
September 07, 2005
  1. · Exception Handling in JavaScript: Introduction to Core Concepts
  2. · Exceptional code: introducing the basics of JavaScript exceptions
  3. · Trapping exceptions: explaining “try-catch” blocks
  4. · A basic example: handling exceptions through a generic mechanism

print this article

Exception Handling in JavaScript: Introduction to Core Concepts
(Page 1 of 4 )

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.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials