From 03260c3e6fd9affaba4a8006bc04966e52265a66 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 31 Oct 2013 07:45:09 -0400 Subject: [PATCH] [Android] Change ConfigFile's get[x] methods to throw IllegalArgumentExceptions instead on NumberFormatExceptions. It was incorrect to throw that exception, since it had nothing to do with how the number was formatted in the string. If a number formatting problem occurred, [type object].parse[type]() methods would throw a NumberFormatException. Also fixed a slight typo in CoreManagerActivity. --- .../coremanager/CoreManagerActivity.java | 2 +- .../browser/preferences/util/ConfigFile.java | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/android/phoenix/src/com/retroarch/browser/coremanager/CoreManagerActivity.java b/android/phoenix/src/com/retroarch/browser/coremanager/CoreManagerActivity.java index f36f5cd4bc..d7e9019487 100644 --- a/android/phoenix/src/com/retroarch/browser/coremanager/CoreManagerActivity.java +++ b/android/phoenix/src/com/retroarch/browser/coremanager/CoreManagerActivity.java @@ -75,7 +75,7 @@ public final class CoreManagerActivity extends ActionBarActivity implements TabL // Do nothing. Not used. } - // Adapter for the CoreView ViewPager class. + // Adapter for the core manager ViewPager. private final class ViewPagerAdapter extends FragmentPagerAdapter { /** diff --git a/android/phoenix/src/com/retroarch/browser/preferences/util/ConfigFile.java b/android/phoenix/src/com/retroarch/browser/preferences/util/ConfigFile.java index 8c57d1b0c0..7bddf0b4d5 100644 --- a/android/phoenix/src/com/retroarch/browser/preferences/util/ConfigFile.java +++ b/android/phoenix/src/com/retroarch/browser/preferences/util/ConfigFile.java @@ -215,14 +215,14 @@ public final class ConfigFile * * @return the Integer value associated with the given key. */ - public int getInt(String key) throws NumberFormatException + public int getInt(String key) { String str = getString(key); if (str != null) return Integer.parseInt(str); else - throw new NumberFormatException(); + throw new IllegalArgumentException("Config key '" + key + "' is invalid."); } /** @@ -232,14 +232,14 @@ public final class ConfigFile * * @return the double value associated with the given key. */ - public double getDouble(String key) throws NumberFormatException + public double getDouble(String key) { String str = getString(key); if (str != null) return Double.parseDouble(str); else - throw new NumberFormatException(); + throw new IllegalArgumentException("Config key '" + key + "' is invalid."); } /** @@ -249,14 +249,14 @@ public final class ConfigFile * * @return the float value associated with the given key. */ - public float getFloat(String key) throws NumberFormatException + public float getFloat(String key) { String str = getString(key); if (str != null) return Float.parseFloat(str); else - throw new NumberFormatException(); + throw new IllegalArgumentException("Config key '" + key + "' is invalid."); } /** @@ -270,6 +270,9 @@ public final class ConfigFile { String str = getString(key); - return Boolean.parseBoolean(str); + if (str != null) + return Boolean.parseBoolean(str); + else + throw new IllegalArgumentException("Config key '" + key + "' is invalid."); } }