1try {
2 // Try to run this code
3}
4catch(err) {
5 // if any error, Code throws the error
6}
7finally {
8 // Always run this code regardless of error or not
9 //this block is optional
10}
1try {
2 // test code
3} catch (error) { // if error
4 console.error(error); // return error
5}
1var someNumber = 1;
2try {
3 someNumber.replace("-",""); //You can't replace a int
4} catch(err) {
5 console.log(err);
6}
1try {
2 // Try to run this code
3}
4catch(err) {
5 // if any error, Code throws the error
6}
7finally {
8
9}
1"The try...catch statement marks a block of statements to try and specifies"
2"a response should an exception be thrown."
3
4try {
5 nonExistentFunction();
6} catch (error) {
7 console.error(error);
8 // expected output: ReferenceError: nonExistentFunction is not defined
9 // Note - error messages will vary depending on browser
10}
11