title: Javascript doesn't catch error in WebSocket instantiation
body: <p>My socket currently throws net::ERR_CONNECTION_REFUSED because the server isn't running, which I want it to do at the moment.</p>
  
  <p>The problem is that the following piece of code doesn't catch the error. In the  console I see an exception on line 2 (with net::ERR_CONNECTION_REFUSED) which I believe shouldn't happen as it's within a try statement.</p>
  
  <pre><code>1  try {
  2    ws = new WebSocket('ws://'+ host + ':' + port + '/');
  3  }
  4  catch (err) {
  5    console.log('This never prints');
  6  }
  7  ws.onerror = function (error) {
  8    console.log(error);
  9  };
  </code></pre>
  
  <p>So my question is why is it not being caught?</p>
  
  <p>What I ultimately want is the error message to be displayed elsewhere, but I can't catch it, and line 8 prints an "event" object which doesn't mention net::ERR_CONNECTION_REFUSED, so I'm not sure how to get the error message out.</p>