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")
You 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.org/en/JavaScript/Reference/Statements/try...catch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With