Using Finally

Another valuable tool in exception handling is the finally keyword. You can add this keyword to the end of a try/catch block. After the try/catch block is executed, the finally block is always executed, whether an error occurs and is caught or the try block is fully executed.

Here’s an example of using a finally block inside a webpage:

function testTryCatch(value){
  try {
    if (value < 0){
      throw "too small";
    } else if (value > 10){
      throw "too big";
    }
    your_code_here
  } catch (err) {
    console.log("The number was " + err);
  } finally {
    console.log("This is always written.");
  }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.165.101