<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Simple try...catch example</title>
  </head>
  <body>
    <script>
      // data from the server
      let json = '{"id":"007", "firstName":"James", "lastName": "Bond"}';

      try {
        // convert the text representation to JS object
        let user = JSON.parse(json);
        // Log the results to console
        console.log(user.id); // 007
        console.log(user.firstName); // James
        console.log(user.lastName); // Bond
      } catch(err) {
        console.log('Error name: ' + err.name);
        console.log('Error message: ' + err.message);
      } finally {
        // This will always execute regardless of success or failure
        console.log('Query finished');
      }
    </script>
  </body>
</html>
