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
Abrarβ€’13mo ago
why that was happened
vince
vinceβ€’13mo 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β€’13mo 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
Abrarβ€’13mo ago
Thanks for the explanation sir
Want results from more Discord servers?
Add your server