473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Actually evaluating 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?

Sep 18 '06 #1
3 1103
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ian Skinner | last post by:
Hopefully this is an easy one, but I'm not sure how to describe it concise enough to Google. I have the following bit of JavaScript: node.childNodes.onclick=function() { showHideAllDivs (...
4
by: louise raisbeck | last post by:
Hi there, I have created a vb server function which i want to evaluate when a server control button is clicked (only!) however it is evaluating the code on load even though i havent put it into the...
4
by: Wade | last post by:
Hi guys, I am building a string in code that is a mathematical formula, based on a lot of criteria specified by the user. Once the formula is complete, I want to evaluate it to get a result. ...
3
by: mike | last post by:
I am using the following script for a function to evaluate a string of data. <script type="text/JavaScript"> function buform1_changed() { ...
2
by: ycoci0 | last post by:
Hi all, Not exactly new to Python, just have not programmed a time dependent function using it before. I imagine that many of you may also program some JavaScript and may be familiar with...
2
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because...
3
by: Sebarry | last post by:
Hi, var primaryKeyToKeyValue = new Array(); for(var i = 0; i < arguments.length; i++) { var len = document.getElementsByName(arguments).options.length;
4
by: jman | last post by:
var x = eval("{ 'flag' : 1 }"); alert(x); alert(x.flag); why doesn't the above work?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.