title: how do I solve a file not found error with java script try catch
body: <p>I'm trying to write some java script code that will (if the file exists) add its content to the web page, if it doesn't exist then it will check if the next file exists. I currently have it displaying the data if the file exists, however throws </p>
  
  <pre><code>GET http://localhost:8080/temp1.xml 404 (Not Found)
  xmlhttp.onreadystatechange @ friends.html:56
  XMLHttpRequest.send (async)
  (anonymous) @ friends.html:95
  </code></pre>
  
  <p>if the file doesn't exist.</p>
  
  <p>I've already tried adding i try catch around different parts but none of them seem to stop the error from occurring. ive also been trying to find a decent guide on how to handle not found errors but cant seem to find one that would work in my case.</p>
  
  <p>this is the code I have without the try excepts.</p>
  
  <pre><code>xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          JSObj = JSON.parse(this.responseText);
          console.log(JSObj.friends.length);
          for (i = 0; i &lt; JSObj.friends.length; i++) {
              name = JSObj.friends[i].name;
              xhttp1.open("GET", "temp"+ i +".xml", true);
              xhttp1.send();
          };
      };
  };
  </code></pre>
  
  <p>this is the code I have with the try excepts </p>
  
  <pre><code>xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          JSObj = JSON.parse(this.responseText);
          console.log(JSObj.friends.length);
          for (i = 0; i &lt; JSObj.friends.length; i++) {
              name = JSObj.friends[i].name;
              try{
                  xhttp1.open("GET", "temp"+ i +".xml", true);
                  xhttp1.send();
             }catch(err){
                  console.log(err);
             };
          };
      };
  };
  </code></pre>
  
  <p>the output I'm getting is a blank page due to the error stopping the code I have working from working which is when the error above is output. I expect that it would just skip that file and go onto the next one.</p>