JS SyntaxError CAN . , , JSON, JSON-. , , , JSON , SyntaxError, JS. , : SyntaxError: JSON Parse error: Unrecognized token '<'.
, . Mozilla : Errors JSON
You may want to catch them in your code. You can do this with a generic try / catch block as follows:
try {
JSON.parse('<html></html>');
} catch (e) {
console.log("I catch & handle all errors the same way.");
}
OR you can search for SyntaxError:
try {
JSON.parse('<html></html>');
} catch (e) {
if (e instanceof SyntaxError) {
console.log("I caught a pesky SyntaxError! I'll handle it specifically here.");
} else {
console.log("I caught an error, but it wasn't a SyntaxError. I handle all non-SyntaxErrors here.");
}
}
Mozilla has even more information about JS errors and how to handle them .
source
share