Welcome to WebmasterWorld Guest from 54.197.171.28

Forum Moderators: open

Message Too Old, No Replies

Error Handling

for JavaScript

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

WebmasterWorld Senior Member 10+ Year Member



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

Josh

Xoc

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

WebmasterWorld Senior Member 10+ Year Member



There is Try and Catch. But it only works on later browsers.
8:25 pm on Nov 1, 2001 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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.