1
0

Handling exceptions

This commit is contained in:
Victor 2014-03-23 19:27:55 +02:00
parent effb0abea9
commit 739191164f
3 changed files with 15 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import com.annimon.turrets.network.GameClient;
import com.annimon.turrets.network.GameServer; import com.annimon.turrets.network.GameServer;
import com.annimon.turrets.network.NetworkListener; import com.annimon.turrets.network.NetworkListener;
import com.annimon.turrets.network.SocketHelper; import com.annimon.turrets.network.SocketHelper;
import com.annimon.turrets.util.ExceptionHandler;
import com.annimon.turrets.util.Util; import com.annimon.turrets.util.Util;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
@ -128,6 +129,7 @@ public class GameCanvas extends DoubleBufferedCanvas implements Runnable, Networ
} }
socketHelper.start(); socketHelper.start();
} catch (IOException ex) { } catch (IOException ex) {
ExceptionHandler.handle(ex);
} }
} }

View File

@ -1,5 +1,6 @@
package com.annimon.turrets; package com.annimon.turrets;
import com.annimon.turrets.util.ExceptionHandler;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
@ -37,7 +38,7 @@ public enum Sound {
clip.open(ais); clip.open(ais);
} }
} catch (IOException | UnsupportedAudioFileException | LineUnavailableException ex) { } catch (IOException | UnsupportedAudioFileException | LineUnavailableException ex) {
ex.printStackTrace(); ExceptionHandler.handle(ex);
} }
return clip; return clip;
} }

View File

@ -1,6 +1,7 @@
package com.annimon.turrets.network; package com.annimon.turrets.network;
import com.annimon.turrets.Turret.TurretInfo; import com.annimon.turrets.Turret.TurretInfo;
import com.annimon.turrets.util.ExceptionHandler;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -41,6 +42,7 @@ public class SocketHelper extends Thread {
break; break;
} }
} catch (IOException ex) { } catch (IOException ex) {
ExceptionHandler.handle(ex);
listener.onStatusChanged(NetworkListener.ON_DISCONNECT, null); listener.onStatusChanged(NetworkListener.ON_DISCONNECT, null);
} }
try { try {
@ -53,7 +55,9 @@ public class SocketHelper extends Thread {
try { try {
dos.writeInt(NetworkListener.ON_SEED_RECEIVED); dos.writeInt(NetworkListener.ON_SEED_RECEIVED);
dos.writeLong(seed); dos.writeLong(seed);
} catch (IOException ex) {} } catch (IOException ex) {
ExceptionHandler.handle(ex);
}
} }
private long receiveSeed() throws IOException { private long receiveSeed() throws IOException {
@ -67,7 +71,9 @@ public class SocketHelper extends Thread {
dos.writeDouble(info.shotPower); dos.writeDouble(info.shotPower);
dos.writeInt(info.barrelX); dos.writeInt(info.barrelX);
dos.writeInt(info.barrelY); dos.writeInt(info.barrelY);
} catch (IOException ex) { } } catch (IOException ex) {
ExceptionHandler.handle(ex);
}
} }
private TurretInfo receiveMove() throws IOException { private TurretInfo receiveMove() throws IOException {
@ -83,7 +89,9 @@ public class SocketHelper extends Thread {
try { try {
dos.writeInt(NetworkListener.ON_NEW_ROUND); dos.writeInt(NetworkListener.ON_NEW_ROUND);
dos.writeLong(seed); dos.writeLong(seed);
} catch (IOException ex) {} } catch (IOException ex) {
ExceptionHandler.handle(ex);
}
} }
public void close() throws IOException { public void close() throws IOException {