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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -