I'm working on connecting to an IRC server currently, and I'm getting an error thrown saying "Error:(20, 16) java: unreported exception java.io.IOException; must be caught or declared to be thrown"
public connection(String host, int port){
this.host = host;
this.port = port;
connect(); //This line is erroring
register();
}
private PrintStream out;
private void connect() throws IOException, UnknownHostException {
Socket socket = new Socket(host, port);
out = new PrintStream(socket.getOutputStream());
}
I have also tried
private PrintStream out;
private void connect() throws IOException, UnknownHostException {
try {
Socket socket = new Socket(host, port);
out = new PrintStream(socket.getOutputStream());
} catch (UnknownHostException ex){
System.out.println(ex.getMessage());
}
}
As well as
private PrintStream out;
private void connect() throws IOException, UnknownHostException {
try {
Socket socket = new Socket(host, port);
try {
out = new PrintStream(socket.getOutputStream());
} catch(IOException exc){
System.out.println(exc.getMessage());
}
} catch (UnknownHostException ex){
System.out.println(ex.getMessage());
}
}
But the error persists through all options that I have tried.