java - How do I declare an exception in an anonymous thread? -
inputstream in = clientsocket.getinputstream(); new thread() { public void run() { while (true) { int = in.read(); handleinput(i); } } }.start();
i'm listening new data on socket code , get:
facenetchat.java:37: unreported exception java.io.ioexception; must caught or declared thrown int = in.read(); ^
when add "throws ioexception" after "run()" get:
facenetchat.java:34: run() in cannot implement run() in java.lang.runnable; overridden method not throw java.io.ioexception public void run() throws ioexception { ^
it's simple, i'm @ loss. how passed this?
you can't override interface of runnable.run() not throw exception. must instead handle exception in run method.
try { int = in.read(); } catch (ioexception e) { // makes sense application }
Comments
Post a Comment