homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Error Handling
for JavaScript

 10:58 am on Nov 1, 2001 (gmt 0)

Does anybody know of a JavaScript equivalent to VBScript's On error resume next?




 6:51 pm on Nov 1, 2001 (gmt 0)

There is Try and Catch. But it only works on later browsers.


 8:25 pm on Nov 1, 2001 (gmt 0)

There is an onError event handler in JavaScript, but it only applies to the Image object -- as you probably know, Josh.

However the Window object also has an onerror property (because its a property, no caps.) You can use this to suppress all error messages and have the code try to resume.

It cannot be attached to HTML tags -- because there is no <window> tag -- it is applied to all js errors in the window. That is, you can't zero in on errors that occur in just one js function if your page runs several.

Place one line of code at the very top of your JavaScript to catch all js errors in that window--

self.onerror = suppress() {return true}

window.onerror is JavaScript 1.1, so this doesn't apply to very old browsers (up through IE4 and NN2, I believe)


 9:22 am on Nov 2, 2001 (gmt 0)

Cheers guys.

Interesting solution tedster - I'd already gone with Try and Catch but I'll be sure to have a tinker with that when I get a chance.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved