title: JavaScript - Try & Catch - Trouble Capturing Window.postMessage() Errors
body: <p>I am having trouble catching errors when using window.postMessage().  </p>
  
  <p>I want to be able to capture the error I am getting - </p>
  
  <p>"Unable to post message to <a href="http://www.that-domain.com">http://www.that-domain.com</a>. Recipient has origin <a href="http://www.this-domain.com">http://www.this-domain.com</a></p>
  
  <p>Simple example code ( should error ):</p>
  
  <pre><code> try {
      window.postMessage('1','http://www.differentDomain.com');
   } 
   catch (e) {       
       alert('error');
   }
  </code></pre>
  
  <p>More detailed process flow:
  I am adding a cross domain iframe to the document with jQuery and then posting to it. This shouldn't error because the target origins should match - they are both set by the proxyDomain variable.</p>
  
  <pre><code>var $iframeProxy = $('&lt;iframe id="myIFrame" src="' + proxyDomain + '"&gt;&lt;/iframe&gt;').appendTo('body');
  
  window.storageProxy = $iframeProxy[0].contentWindow;
  
  try {
      window.storageProxy.postMessage(message, proxyDomain);
  }
  catch (e) {       
      alert('error');
  }
  </code></pre>