Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  45] [ 4]  / answers: 1 / hits: 58922  / 14 Years ago, mon, february 7, 2011, 12:00:00

I wanted to know if it is possible to find through javascript if a call to eval() has a syntax error or undefined variable, etc... so lets say I use eval for some arbitrary javascript is there a way to capture the error output of that eval?


More From » eval

 Answers
117

You can test to see if an error is indeed a SyntaxError.



try {
eval(code);
} catch (e) {
if (e instanceof SyntaxError) {
alert(e.message);
}
}

[#93858] Saturday, February 5, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leandraannabellar

Total Points: 255
Total Questions: 89
Total Answers: 89

Location: England
Member since Sun, May 21, 2023
1 Year ago
;