SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Custom Error Handling
By Scott Isaacs

I often hear web-developers say how easy it is to write script and that anyone can do it. In reality, writing a robut script can be fairly difficult. You are using a language that currently has very limited exception handling in an asynchronous, unpredictable environment. You need to recognize that your pages are being delivered over an unpredictable pipe at an unpredictable speed to an unpredictable environment. Even if underneath the hoods everything runs smoothly, the user can throw off everything just by hitting their stop button. Even when scripts are predictable, the behavior is often not correctly handled. For example, did you know some scripts may execute before the page is fully loaded? In general, lots of things can go wrong.

A few months back we published an article on Scripting Defensively. In Scripting Defensively, we showed you various scripting techniques for testing whether the page is ready to run. In this article, we focus on what to do when that inevitable script error occurs. No matter how hard we try, they always seem to pop-up messing up pages and confusing users. Until we are all perfect programmers and the internet becomes more robust, we need to find a way to live with the occasional script error. However, having to live with script errors does not mean you have to live with the browser's built-in handling. Instead, why not create your own custom error message? Today we show you how.