Try . . . Catch in JavaScript
Posted by admin on April 19, 2008
Note to myself: The try / catch statement only works in web browsers that are capable of running at least JavaScript 1.3.
If you try to run “try / catch” statements in older web browsers, you get a JavaScript message (or, as your end users will point out, “a browser error”), stating something the lines of: try is a reserved identifier.
FYI:
IE6 and IE7 support JavaScript 1.3.
Firefox 1 and Firefox 2 support JavaScript 1.5.
If you want to make absolutely sure that your “try / catch” statements don’t cause errors for those end user’s with older web browsers (yes, they do exist), you could use the following statement in your < script > tag:
language=”JavaScript1.3″ . . .
Unsure about your web browser’s JavaScript capabilities? Check out The language attribute of JavaScript, run by the friendly folks from JavaScript Kit, which contains JavaScript code to test versions up to 2.0.
Filed Under: JavaScript, Web Design and Development