Commit 73d72870 authored by Matti Pulkkinen's avatar Matti Pulkkinen
Browse files

don't throw IOException out of main

parent ab3349a8
......@@ -4,25 +4,39 @@ import java.io.IOException;
public class Main {
// TODO don't throw IOException
public static void main(String[] args) throws IOException {
SocketHandler socketHandler = new SocketHandler();
StreamHandler sh = socketHandler.openStreamHandler();
public static void main(String[] args) {
SocketHandler socketHandler = null;
StreamHandler streamHandler = null;
try {
socketHandler = new SocketHandler();
} catch (IOException e) {
System.err.println("Failed to create SocketHandler object.");
e.printStackTrace();
System.exit(1);
}
try {
streamHandler = socketHandler.openStreamHandler();
} catch (IOException e) {
System.err.println("Failed to open StreamHandler.");
e.printStackTrace();
System.exit(1);
}
int t = 0;
try {
t = sh.readInt();
t = streamHandler.readInt();
System.err.println("Received t = " + t);
} catch (IOException e) {
System.err.println("Failed in reading t through ObjectInputStream.");
System.err.println("Failed to read int through ObjectInputStream.");
e.printStackTrace();
}
if (t < 2 || t > 10) {
System.err.println("Illegal value t, sending response...");
try {
sh.writeInt(-1);
streamHandler.writeInt(-1);
} catch (IOException e) {
System.out.println("Failed in sending response for illegal value.");
System.out.println("Failed to send response for illegal value.");
e.printStackTrace();
System.exit(2);
}
......@@ -30,10 +44,6 @@ public class Main {
System.exit(2);
}
for (int i = 0; i < t; i++) {
int r = (int) (Math.random() * 5000 + 1024); // TODO ensure no duplicates
sh.writeInt(r);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment