I create a let calc = new Function(return ${strExpression};); I want to check syntax of calc before run or caught SyntaxError raised by calc();
I tried:
function compute(strExpression){
let calc = new Function(`return ${strExpression};`);
try {
result = calc();
return result;
} catch (error) {
return null;
}
}
For some invaild strExpression I could get an error and in this case I see SyntaxError on console but catch doesn't work.
Functioncall, not thecalccall. Put everthing within thetryblock.