Wouldn't a developer's life be easy if there were never any errors in it. Or would it? Might get a bit boring after a while if there was never that buzz of finally finding the source of your woes after hours pulling at your hair. No matter what your outlook, as professionals we should always try our best to avoid them ever happening.
Obviously we can't guarantee they will never happen. What we can do though is make sure that when they do it is as painless as possible for the user. If that user also happens to be a customer then this becomes even more important.
Handling errors:
Internet Explorer 5 and Netscape 6 have introduced Exception handling to their JavaScript implementations. This means that we can see when an error has occurred and deal with it accordingly. Let's see how:
function notVeryWellDesigned( foo ){Being a fool I have accidentally typed alert with a capital A. Being case-sensitive, JavaScript isn't going to like this. See what your browser thinks of it here.
try
{
Alert( foo );
}
catch (exception)
{
if (exception.description == null) {
alert("Exception: " + exception.message);
}
else
{
alert("Exception: " + exception.description);
}
}
}
function tryAndGetNameOfViewInApplet()So there you go. You can now make your web applications handle problems a lot more gracefully and keep your professional integrity whilst your at it....
{
alert(document.applets.view.getViewName());
}
catch (exception)
{
window.status="Waiting for view\'s applet to load...";
setTimeout("tryAndGetNameOfViewInApplet()",500);
}
Copyright © 2000 - 2024 Jake Howlett of Rockall Design ltd. This article was printed from codestore.net