1

I have this piece of code:

private void handleReceivedMessage(String m) throws IOException {
    switch(m) {
        case "ping":
            // code block
            ping();
            break;
        default:
            System.out.println("message not understood");
    }

}
public DataServer(int port) throws IOException {
        server = new Server(port, this::handleReceivedMessage);
        server.acceptClient();
}

now I get the error at the line this::handleReceivedMessage: Unhandled exception: java.io.IOException

How do I solve this? It's clear that the handleReceivedMessage functions does throw an IOException

1 Answers1

1

Without knowing more, I'd try using a try/catch statement specifically to catch the exception being thrown as Olivier is suggesting. If may I ask, why aren't you using try/catch for error checking?

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39