I am trying to catch a Syntax error in my code, but it does not get into catch block
( function(){
try {
throw fn(){}; // I am trying to generate some syntax error here
}catch (exception){
console.log(exception.message);
}
})();
Edited
If you notice here the wrong syntax is inside the try block, so as a javascript theory it has to first go inside catch block, then whats use of a built-in object SyntaxError
( function(){
try {
throw fn(){};
}catch (exception){
if(exception instanceof SyntaxError)
console.log("Syntax Exception occured" + exception.message);
}
})();
but this is not handled in program instead I am able to see "Uncaught SyntaxError" directly in console
Uncaught SyntaxError: Unexpected token {
at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)
jslintjslint.com