unreported exception java.io.IOException -


what's wrong code

import java.io.ioexception; import java.net.serversocket; import java.net.socket;  /**  *  * @author master  */ public class server {     try     {     serversocket s = new serversocket(3333);     socket = s.accept();     }     catch(ioexception e)     {         system.out.println("ioerror");     }  } 

firstly wrote code without try catch , got unreported exception java.io.ioexception; must caught or declared thrown error netbeans didn't suggest add try-catch block . added try-catch block manually still shows error , suggests must add try-catch block !

alt text

you're trying add try block @ top level of class - can't that. try blocks have in methods or initializer blocks.

if really want create server socket on construction, put code in constructor:

public class server {      private serversocket serversocket;     private socket firstconnection;      public server {         try         {             serversocket = new serversocket(3333);             firstconnection = serversocket.accept();         }         catch(ioexception e)         {             system.out.println("ioerror");         }     } } 

i assume you'll have real exception handling (or rethrowing) rather catching ioexception , continuing, of course?


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -