title: How to get a try/catch error in Javascript when file doesn't exist?
body: <p>I replace a background image using Javascript in an element by calling a <strong>local</strong> file (not a URL).</p>
  
  <p>I want to try to catch an error if this file does not exist. </p>
  
  <p>So I tried the following code:</p>
  
  <pre><code>    try {
          thing.style.backgroundImage = str;
      }
      catch (err) {
          console.log(err.message);
          thing.style.backgroundImage = "none";
      }
  </code></pre>
  
  <p>However, even nonesense file names seem to pass and no error is generated. Even worse, sometimes the background image displayed is empty and sometimes it is an image from a previous call.</p>
  
  <p>Is there any way to try/catch an error here?</p>