error handling

<!DOCTYPE html> <html> <body> </body> <script> try{ for(a = 2,a < 2;a++){ console.log(a); } catch (err) { console.log("Syntax Error Was Occured"); } </script> </html> from above example there was syntax error on for loop then i try to catch the error and it doesn't work
5 Replies
Abrar
AbrarOPβ€’15mo ago
why that was happened
vince
vinceβ€’15mo ago
let a = 2
Chooβ™šπ•‚π•šπ•Ÿπ•˜
for(let a = 2; a < 2; a++){
console.log(a);
}
for(let a = 2; a < 2; a++){
console.log(a);
}
Jochem
Jochemβ€’15mo ago
try-catch doesn't catch syntax errors, because they occur before code execution and make code execution impossible. try-catch only catches exceptions, which are runtime errors
Abrar
AbrarOPβ€’15mo ago
Thanks for the explanation sir
Want results from more Discord servers?
Add your server