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 !
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
Post a Comment