title: How do try...catch statements really work in IE?
body: <p>I have a <code>foreach()</code> loop in this function and by searching the internet I know, that for each loop doesn't work in IE.
  To save my time I simply put a: <code>try {} catch {}</code> around it, but IE still reminds me, by function call, that there is an error.</p>
  <p>Why does IE 11 work ? <strong>Code:</strong></p>
  <p>Code:</p>
  <pre><code>function classAndIdSpy() {
  
  var req = new XMLHttpRequest();
  var x = document.getElementsByClassName(&quot;spy&quot;);
  var page_you_on = window.location.href.split(&quot;/&quot;);
  var json56 = '{ &quot;div_ids_classes&quot; : [{&quot;PAGE&quot;:&quot;'+page_you_on[page_you_on.length-1]+'&quot;},';
  
  try {
     // Block of code to try. 
  for(var xy of x) { 
  
  json56 += '{&quot;SPY_ID&quot;:&quot;'+xy.id+'&quot;,&quot;CLASS&quot;:&quot;'+xy.parentNode.className+'&quot;,&quot;ID&quot;:&quot;'+xy.parentNode.id +'&quot;}';
  
  json56 += (x.length-1 &gt; [].indexOf.call(x, xy)) ? ',' : '';
  
  }
  json56 += ']}';
  
  req.open('POST', '../admin/id_class_colect.php', true);
  req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  req.send(&quot;json2=&quot;+json56);
  
  var status;
  req.onreadystatechange = function() {//Call a function when the state changes.
      if(req.readyState == 4 &amp;&amp; req.status == 200) {
          status = req.responseText;        
          console.log(&quot;Send ajax. Colected Id and Class information of content DIVs into database. Status:&quot;+status);         
      }}
  }
  catch(err) {
        console.log(&quot;Your browser doesn't support ID and Class information of content DIV into database. Please use another browser.&quot;);
         return false;   
     } 
  } //End of ClassAndIDspy
  </code></pre>
  <p><strong>I get the following error in the console: SCRIPT1004: Expected ';' (The function works fine in Firefox, and I don't think there is a semicolon missing)</strong></p>
  <p>And, this is the part I would like Internet Exporer to ignore:
  <strong>Code:</strong></p>
  <pre><code>for(var xy of x) { 
  
  json56 += '{&quot;SPY_ID&quot;:&quot;'+xy.id+'&quot;,&quot;CLASS&quot;:&quot;'+xy.parentNode.className+'&quot;,&quot;ID&quot;:&quot;'+xy.parentNode.id +'&quot;}';
  
  json56 += (x.length-1 &gt; [].indexOf.call(x, xy)) ? ',' : '';
  
  }
  </code></pre>
  <p>Thank you for any help !</p>