Commit daf469e2 by Warren Levy Committed by Warren Levy

DecimalFormat.java: Throw IllegalArgumentException throughout rather than ParseException.

	* java/text/DecimalFormat.java: Throw IllegalArgumentException
	throughout rather than ParseException.

From-SVN: r27481
parent 8c84eeed
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
IOException. IOException.
* java/text/Collator.java (CANONICAL_DECOMPOSITION): Fixed typo * java/text/Collator.java (CANONICAL_DECOMPOSITION): Fixed typo
in static field name. in static field name.
* java/text/DecimalFormat.java: Throw IllegalArgumentException
throughout rather than ParseException.
1999-06-09 Bryce McKinlay <bryce@albatross.co.nz> 1999-06-09 Bryce McKinlay <bryce@albatross.co.nz>
......
...@@ -32,7 +32,6 @@ public class DecimalFormat extends NumberFormat ...@@ -32,7 +32,6 @@ public class DecimalFormat extends NumberFormat
private final int scanFix (String pattern, int index, StringBuffer buf, private final int scanFix (String pattern, int index, StringBuffer buf,
String patChars, DecimalFormatSymbols syms, String patChars, DecimalFormatSymbols syms,
boolean is_suffix) boolean is_suffix)
throws ParseException
{ {
int len = pattern.length(); int len = pattern.length();
buf.setLength(0); buf.setLength(0);
...@@ -65,7 +64,8 @@ public class DecimalFormat extends NumberFormat ...@@ -65,7 +64,8 @@ public class DecimalFormat extends NumberFormat
else if (is_suffix && c == syms.getPercent()) else if (is_suffix && c == syms.getPercent())
{ {
if (multiplierSet) if (multiplierSet)
throw new ParseException ("multiplier already set", index); throw new IllegalArgumentException ("multiplier already set " +
"- index: " + index);
multiplierSet = true; multiplierSet = true;
multiplier = 100; multiplier = 100;
buf.append(c); buf.append(c);
...@@ -73,7 +73,8 @@ public class DecimalFormat extends NumberFormat ...@@ -73,7 +73,8 @@ public class DecimalFormat extends NumberFormat
else if (is_suffix && c == syms.getPerMill()) else if (is_suffix && c == syms.getPerMill())
{ {
if (multiplierSet) if (multiplierSet)
throw new ParseException ("multiplier already set", index); throw new IllegalArgumentException ("multiplier already set " +
"- index: " + index);
multiplierSet = true; multiplierSet = true;
multiplier = 1000; multiplier = 1000;
buf.append(c); buf.append(c);
...@@ -95,7 +96,6 @@ public class DecimalFormat extends NumberFormat ...@@ -95,7 +96,6 @@ public class DecimalFormat extends NumberFormat
private final int scanFormat (String pattern, int index, private final int scanFormat (String pattern, int index,
String patChars, DecimalFormatSymbols syms, String patChars, DecimalFormatSymbols syms,
boolean is_positive) boolean is_positive)
throws ParseException
{ {
int max = pattern.length(); int max = pattern.length();
...@@ -113,7 +113,8 @@ public class DecimalFormat extends NumberFormat ...@@ -113,7 +113,8 @@ public class DecimalFormat extends NumberFormat
if (c == syms.getDigit()) if (c == syms.getDigit())
{ {
if (zeroCount > 0) if (zeroCount > 0)
throw new ParseException ("digit mark following zero", index); throw new IllegalArgumentException ("digit mark following " +
"zero - index: " + index);
++countSinceGroup; ++countSinceGroup;
} }
else if (c == syms.getZeroDigit()) else if (c == syms.getZeroDigit())
...@@ -163,8 +164,8 @@ public class DecimalFormat extends NumberFormat ...@@ -163,8 +164,8 @@ public class DecimalFormat extends NumberFormat
if (c == syms.getZeroDigit()) if (c == syms.getZeroDigit())
{ {
if (hashCount > 0) if (hashCount > 0)
throw new ParseException ("zero mark following digit", throw new IllegalArgumentException ("zero mark " +
index); "following digit - index: " + index);
++zeroCount; ++zeroCount;
} }
else if (c == syms.getDigit()) else if (c == syms.getDigit())
...@@ -174,8 +175,8 @@ public class DecimalFormat extends NumberFormat ...@@ -174,8 +175,8 @@ public class DecimalFormat extends NumberFormat
else if (c != syms.getExponential() else if (c != syms.getExponential()
&& c != syms.getPatternSeparator() && c != syms.getPatternSeparator()
&& patChars.indexOf(c) != -1) && patChars.indexOf(c) != -1)
throw new ParseException ("unexpected special character", throw new IllegalArgumentException ("unexpected special " +
index); "character - index: " + index);
else else
break; break;
...@@ -208,11 +209,13 @@ public class DecimalFormat extends NumberFormat ...@@ -208,11 +209,13 @@ public class DecimalFormat extends NumberFormat
{ {
if (zeroCount > 0) if (zeroCount > 0)
throw new throw new
ParseException ("digit mark following zero in exponent", IllegalArgumentException ("digit mark following zero " +
"in exponent - index: " +
index); index);
} }
else if (patChars.indexOf(c) != -1) else if (patChars.indexOf(c) != -1)
throw new ParseException ("unexpected special character", throw new IllegalArgumentException ("unexpected special " +
"character - index: " +
index); index);
else else
break; break;
...@@ -253,7 +256,6 @@ public class DecimalFormat extends NumberFormat ...@@ -253,7 +256,6 @@ public class DecimalFormat extends NumberFormat
private final void applyPatternWithSymbols (String pattern, private final void applyPatternWithSymbols (String pattern,
DecimalFormatSymbols syms) DecimalFormatSymbols syms)
throws ParseException
{ {
// Initialize to the state the parser expects. // Initialize to the state the parser expects.
negativePrefix = ""; negativePrefix = "";
...@@ -292,7 +294,8 @@ public class DecimalFormat extends NumberFormat ...@@ -292,7 +294,8 @@ public class DecimalFormat extends NumberFormat
else else
{ {
if (pattern.charAt(index) != syms.getPatternSeparator()) if (pattern.charAt(index) != syms.getPatternSeparator())
throw new ParseException ("separator character expected", index); throw new IllegalArgumentException ("separator character " +
"expected - index: " + index);
index = scanFix (pattern, index + 1, buf, patChars, syms, false); index = scanFix (pattern, index + 1, buf, patChars, syms, false);
negativePrefix = buf.toString(); negativePrefix = buf.toString();
...@@ -305,17 +308,26 @@ public class DecimalFormat extends NumberFormat ...@@ -305,17 +308,26 @@ public class DecimalFormat extends NumberFormat
negativeSuffix = buf.toString(); negativeSuffix = buf.toString();
if (index != pattern.length()) if (index != pattern.length())
throw new ParseException ("end of pattern expected", index); throw new IllegalArgumentException ("end of pattern expected " +
"- index: " + index);
} }
} }
public void applyLocalizedPattern (String pattern) throws ParseException public void applyLocalizedPattern (String pattern)
{ {
// JCL p. 638 claims this throws a ParseException but p. 629
// contradicts this. Empirical tests with patterns of "0,###.0"
// and "#.#.#" corroborate the p. 629 statement that an
// IllegalArgumentException is thrown.
applyPatternWithSymbols (pattern, symbols); applyPatternWithSymbols (pattern, symbols);
} }
public void applyPattern (String pattern) throws ParseException public void applyPattern (String pattern)
{ {
// JCL p. 638 claims this throws a ParseException but p. 629
// contradicts this. Empirical tests with patterns of "0,###.0"
// and "#.#.#" corroborate the p. 629 statement that an
// IllegalArgumentException is thrown.
applyPatternWithSymbols (pattern, nonLocalizedSymbols); applyPatternWithSymbols (pattern, nonLocalizedSymbols);
} }
...@@ -351,17 +363,8 @@ public class DecimalFormat extends NumberFormat ...@@ -351,17 +363,8 @@ public class DecimalFormat extends NumberFormat
public DecimalFormat (String pattern, DecimalFormatSymbols symbols) public DecimalFormat (String pattern, DecimalFormatSymbols symbols)
{ {
this.symbols = symbols; this.symbols = symbols;
// The docs imply that the constructor turns a ParseException
// into an IllegalArgumentException.
try
{
applyPattern (pattern); applyPattern (pattern);
} }
catch (ParseException x)
{
throw new IllegalArgumentException (x.getMessage());
}
}
private final boolean equals (String s1, String s2) private final boolean equals (String s1, String s2)
{ {
......
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