try catch finally code example
Example 1: blank catch js
try {
try_statements
}
[catch [(exception_var)] {
catch_statements
}]
[finally {
finally_statements
}]
Example 2: try-catch-finally
localStorage.getItem(key)
try {
data = JSON.parse(key)
}
catch (e) {
// if the code errors, this bit of code will run
}
finally {
return data
}
Example 3: try catch javascript
try {
alert('Start of try runs'); // (1) <--
lalala; // error, variable is not defined!
alert('End of try (never reached)'); // (2)
} catch(err) {
alert(`Error has occurred!`); // (3) <--
}