Catch error in WebSocket constructor instantiation - Javascript Language Basics

Javascript examples for Language Basics:WebSocket

Description

Catch error in WebSocket constructor instantiation

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w w  w  .  jav a2  s.  c  o m
host='localhost';
port=100;
try {
    ws = new WebSocket('ws://'+ host + ':' + port + '/');
}
catch (err) {
    console.log('This never prints');
}
ws.onerror = function (error) {
    console.log(error);
};
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials