Exception Handling in JavaScript: Addressing Browser Incompatibilities
(Page 1 of 5 )
Not all browsers handle all code the same way. Differences can be addressed with JavaScript exceptions. These may not be the best way under all circumstances, but you'll find it worthwhile to examine this approach.
Introduction
Welcome to the last part of the series “Exception Handling in JavaScript.” As you might guess, I’m winding up this tutorial focused on exploring the huge terrain of JavaScript exceptions, by running through numerous examples about their application in real client programs. Indeed, the topic is by far more extensive than can be treated in a few articles, thus complete coverage is nearly impossible. However, I’ve explained in a friendly way the basics of exceptions, by introducing their core concepts as well as their direct implementation in concrete cases.
With reference to a practical application, in my previous article I offered an introduction to using custom error objects in a classic situation -- client-side form validation -- by tackling the issue from a different point of view, certainly distinct from traditional form verification techniques. Whether you use JavaScript as part of overall data validation processes (remember that server-side checking is a must), or simply for adding pre-defined behaviors to the structure of web documents, exceptions can be used to handle errors in a more professional way, by utilizing popular “try-catch” blocks.
Since most of the examples that I’ve shown through this series are aimed at providing you with the required background to use exceptions in practical cases, over this last part I’ll continue sticking to that approach by demonstrating particularly how some browser incompatibilities can be addressed with exceptions. Of course, I’m not claiming this method is the best way to deal with all browser inconsistencies, but certainly it does offer an alternative method that’s worth reviewing.
Now that you know what this last part of the series is about, let’s see a few examples that use exceptions for solving some browser-related incompatibilities.
Next: JavaScript-based http requests: implementing cross-browser object instantiation >>
More JavaScript Articles
More By Alejandro Gervasio