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
why that was happened
let a = 2
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
Thanks for the explanation sir