Revision: 6414 Author: j...@google.com Date: Sun Oct 18 11:53:33 2009 Log: Fix bad error message from NumberFormat.parse.
Patch by: jat Review by: jlabanca http://code.google.com/p/google-web-toolkit/source/detail?r=6414 Modified: /trunk/user/src/com/google/gwt/i18n/client/NumberFormat.java /trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java ======================================= --- /trunk/user/src/com/google/gwt/i18n/client/NumberFormat.java Fri May 29 12:15:37 2009 +++ /trunk/user/src/com/google/gwt/i18n/client/NumberFormat.java Sun Oct 18 11:53:33 2009 @@ -1076,8 +1076,12 @@ } } - // parseDouble could throw NumberFormatException, let it do it. - ret = Double.parseDouble(normalizedText.toString()); + // parseDouble could throw NumberFormatException, rethrow with correct text. + try { + ret = Double.parseDouble(normalizedText.toString()); + } catch (NumberFormatException e) { + throw new NumberFormatException(text); + } ret = ret / scale; return ret; } ======================================= --- /trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java Tue Jun 23 20:13:51 2009 +++ /trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java Sun Oct 18 11:53:33 2009 @@ -285,6 +285,15 @@ str = NumberFormat.getFormat("#,##0.00;-# X").format(-1014.336); assertEquals("-1,014.34 X", str); } + + public void testParseNotANumber() { + try { + double d = NumberFormat.getDecimalFormat().parse("blue"); + fail("Expected a NumberFormatException"); + } catch (NumberFormatException e) { + assertEquals("blue", e.getMessage()); + } + } public void testPercent() { String str; --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---