0

I recieve 3 errors in the following section of code:

public static void main(String[] args){

     CS_Socket cs = new CS_Socket();

     try{
         new Thread(() -> cs.EchoServer()).start();
         new Thread(() -> cs.EchoClient()).start();
       }

     catch(IOException e){

       System.out.println(e.getMessage());

     }
}

For both new threads, I receive unreported exception java.io.IOException; must be caught or declared to be thrown as a compiler error.

In catch(IOException e), I receive exception java.io.IOException is never thrown in body of corresponding try statement.

I'm new to Java and have no idea how to fix these errors. None of the other questions about these errors seem to contain answers relevant to my code.

Any help is greatly appreciated.

Daniyal Syed
  • 543
  • 4
  • 22
AKMan6
  • 35
  • 3
  • Put your `try{` before the `CS_Socket` line, it is probably this line that may throw an `IOException` . – Arnaud Jun 15 '17 at 07:40
  • @Berger Nope, I still get the errors. – AKMan6 Jun 15 '17 at 07:42
  • looks like `CS_Socket.EchoServer()` and `CS_Socket.EchoClient()` are the methods that need a `catch()` statement. It would help if you could post the code for class `CS_Socket` – Lolo Jun 15 '17 at 12:44

1 Answers1

-1

Exception thrown in a thread normally couldn't be caught in another thread.

See this link for more explanation How to catch an Exception from a thread

Sumit
  • 729
  • 4
  • 9