[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.
This commit is contained in:
Lioncash 2013-10-31 07:45:09 -04:00
parent e11b678ddd
commit 03260c3e6f
2 changed files with 11 additions and 8 deletions

View File

@ -75,7 +75,7 @@ public final class CoreManagerActivity extends ActionBarActivity implements TabL
// Do nothing. Not used. // Do nothing. Not used.
} }
// Adapter for the CoreView ViewPager class. // Adapter for the core manager ViewPager.
private final class ViewPagerAdapter extends FragmentPagerAdapter private final class ViewPagerAdapter extends FragmentPagerAdapter
{ {
/** /**

View File

@ -215,14 +215,14 @@ public final class ConfigFile
* *
* @return the Integer value associated with the given key. * @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); String str = getString(key);
if (str != null) if (str != null)
return Integer.parseInt(str); return Integer.parseInt(str);
else 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. * @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); String str = getString(key);
if (str != null) if (str != null)
return Double.parseDouble(str); return Double.parseDouble(str);
else 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. * @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); String str = getString(key);
if (str != null) if (str != null)
return Float.parseFloat(str); return Float.parseFloat(str);
else else
throw new NumberFormatException(); throw new IllegalArgumentException("Config key '" + key + "' is invalid.");
} }
/** /**
@ -270,6 +270,9 @@ public final class ConfigFile
{ {
String str = getString(key); String str = getString(key);
if (str != null)
return Boolean.parseBoolean(str); return Boolean.parseBoolean(str);
else
throw new IllegalArgumentException("Config key '" + key + "' is invalid.");
} }
} }