Handle NumberFormatExceptions from parseInt()

This commit is contained in:
Cameron Gutman 2015-02-11 17:24:27 -05:00
parent 7ae74a6a18
commit fe907b0271
2 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,7 @@
package com.limelight.nvstream.http;
import com.limelight.LimeLog;
public class NvApp {
private String appName = "";
private int appId;
@ -11,8 +13,12 @@ public class NvApp {
}
public void setAppId(String appId) {
this.appId = Integer.parseInt(appId);
this.initialized = true;
try {
this.appId = Integer.parseInt(appId);
this.initialized = true;
} catch (NumberFormatException e) {
LimeLog.warning("Malformed app ID: "+appId);
}
}
public void setIsRunning(String isRunning) {

View File

@ -6,6 +6,7 @@ import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
import com.limelight.LimeLog;
import com.limelight.nvstream.http.ComputerDetails;
public class WakeOnLanSender {
@ -45,7 +46,12 @@ public class WakeOnLanSender {
@SuppressWarnings("resource")
Scanner scan = new Scanner(macAddress).useDelimiter(":");
for (int i = 0; i < macBytes.length && scan.hasNext(); i++) {
macBytes[i] = (byte) Integer.parseInt(scan.next(), 16);
try {
macBytes[i] = (byte) Integer.parseInt(scan.next(), 16);
} catch (NumberFormatException e) {
LimeLog.warning("Malformed MAC address: "+macAddress+" (index: "+i+")");
break;
}
}
scan.close();
return macBytes;