By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

Actually evaluating javascript...

P: n/a
Is there a way to do some sort of try{}catch(){} thing where I can eval
a function. Basically, I want to overcome the errors that get printed
out, almost like a production mode for my code, where I can catch the
invalid javascript, and return something like, "Sorry, an error has
occurred". Does this make sense?

Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Volte wrote on 18 sep 2006 in comp.lang.javascript:
Is there a way to do some sort of try{}catch(){} thing where I can eval
a function. Basically, I want to overcome the errors that get printed
out, almost like a production mode for my code, where I can catch the
invalid javascript, and return something like, "Sorry, an error has
occurred". Does this make sense?
No, it does not.

Thorough testing and modular programming,
sharp validating of all input variables,
should make your programme sound.

try{}catch(){} can only grracefully back out from an error,
if you know the kind of error expected,
and so has only very linmited use in a "production" environment.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 18 '06 #2

P: n/a
On 18 Sep 2006 20:15:55 GMT, "Evertjan."
<ex**************@interxnl.netwrote:
>try{}catch(){} can only grracefully back out from an error,
if you know the kind of error expected,
and so has only very linmited use in a "production" environment.
except of couse in script, where the speed advantages gainable in
using try/catch can be huge.

e.g. if you want to get an optional value from an xml document

try {

x=element.getElementsByTagNameNS(chickenNS,"egg")[0].firstChild.nodeValue;
} catch (e) {
x="hen";
}

is much faster than checking every part. certianly there's a chance
you will catch another error, which shouldn't be caught - but it's not
too likely assuming you've also already tested the other likely
failures.

Jim.
Sep 18 '06 #3

P: n/a
Jim Ley wrote on 18 sep 2006 in comp.lang.javascript:
On 18 Sep 2006 20:15:55 GMT, "Evertjan."
<ex**************@interxnl.netwrote:
>>try{}catch(){} can only grracefully back out from an error,
if you know the kind of error expected,
and so has only very linmited use in a "production" environment.

except of couse in script, where the speed advantages gainable in
using try/catch can be huge.

e.g. if you want to get an optional value from an xml document

try {

x=element.getElementsByTagNameNS(chickenNS,"egg")[0].firstChild.nodeVal
ue;
} catch (e) {
x="hen";
}

is much faster than checking every part. certianly there's a chance
you will catch another error, which shouldn't be caught - but it's not
too likely assuming you've also already tested the other likely
failures.
That was why I wrote "linmited use", slipping of the keyboard in the mean
time.

But the question was a general one, and was probably founded on the horror
scenario use of "on error resume" next to the "option explicit" in basic,
vb or vbs.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.