- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript try catch
JavaScript Errors
JavaScript try catch
tryruns code that might fail, andcatchhandles it when it does.
If nothing goes wrong, the catch block never runs.
If something does, execution jumps there immediately.
Example
Example
javascript
let result;
try {
result = JSON.parse("not json");
} catch (error) {
result = "could not parse that";
}
console.log(result);The output is could not parse that.
