Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Weird error with try catch block.

843810Jun 14 2003 — edited Jun 20 2007
Hi all. I'm getting a error when I compile the code bellow. javac spits out: exception java.io.IOException is never thrown in body of corresponding try statement: catch(IOException e4) {

I've looked and looked but I can't find where I'm going wrong. It really ticks me off. Anyways, thanks for your time and here's the code:
import java.io.*;
import java.net.*;

public class FRClient {

public static void main(String args[]) {
Socket server = null;
PrintWriter pw = null;
String filename = args[0];
try {
	server = new Socket("192.168.2.5",1234);
}
catch(UnknownHostException e) {
	System.err.println("Unknown host: " + e);
}
catch(IOException e) {
	System.err.println("Error creating socket: " + e);
}
try {
	pw = new PrintWriter(new OutputStreamWriter(server.getOutputStream()));
}
catch(IOException e2) {
	System.err.println("Error creating writer: " + e2);
}
try {
	File source = new File(filename);
	FileReader fr = new FileReader(source);
	BufferedReader fileReader = new BufferedReader(fr);
	String line = null;
	while((line = fileReader.readLine()) != null) {
		pw.println(line);
	}
	fileReader.close();
}
catch(FileNotFoundException e) {
	System.err.println("File not found.");
}
catch(IOException e3) {
	System.err.println("Error reading or sending file: " + e3);
}
finally {
	try {
		pw.flush();
		pw.close();
	}
	catch(IOException e4) { \\here is where I get the error
		System.err.println(e4);
	}
}
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2007
Added on Jun 14 2003
4 comments
289 views