I'm trying to execute JavaScript from plain text (from being entered by a client). I also need a way to see if the executed code works or not (if it does, then it does, otherwise, it needs to spit out a non-variable error message).
Thanks if you can! The stuff that will be executed would be short strings such as:
echo("a","b")
I'm trying to execute JavaScript from plain text (from being entered by a client). I also need a way to see if the executed code works or not (if it does, then it does, otherwise, it needs to spit out a non-variable error message).
Thanks if you can! The stuff that will be executed would be short strings such as:
echo("a","b")
Share
Improve this question
edited May 3, 2014 at 0:16
Chris
1,42618 silver badges29 bronze badges
asked May 13, 2011 at 17:04
FreesnöwFreesnöw
32.2k31 gold badges94 silver badges140 bronze badges
2 Answers
Reset to default 8You can use eval and wrap around try-catch.
try
{
eval(code);
}
catch(err)
{
//Handle errors here
}
Are you saying you just need a try/catch statement?
https://developer.mozilla/en/JavaScript/Reference/Statements/try...catch