classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: java.lang.Integer exception clarification


From: Guilhem Lavaux
Subject: [cp-patches] FYI: java.lang.Integer exception clarification
Date: Sun, 04 Sep 2005 11:43:29 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050322)

Hi,

here is a small patch to add some clarification messages to why some exceptions are thrown in java.lang.Integer. They may be useful when debugging large applications like eclipse. I am checking it in now.

Regards,

Guilhem.

2005-09-04  Guilhem Lavaux  <address@hidden>

        * java/lang/Integer.java
        (parseInt): Added some messages to the exception thrown by
        this method.

Index: java/lang/Integer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Integer.java,v
retrieving revision 1.32
diff -u -r1.32 Integer.java
--- java/lang/Integer.java      2 Jul 2005 20:32:38 -0000       1.32
+++ java/lang/Integer.java      4 Sep 2005 09:40:20 -0000
@@ -718,12 +718,12 @@
     int len = str.length();
     boolean isNeg = false;
     if (len == 0)
-      throw new NumberFormatException();
+      throw new NumberFormatException("string length is null");
     int ch = str.charAt(index);
     if (ch == '-')
       {
         if (len == 1)
-          throw new NumberFormatException();
+          throw new NumberFormatException("pure '-'");
         isNeg = true;
         ch = str.charAt(++index);
       }
@@ -748,7 +748,7 @@
           }
       }
     if (index == len)
-      throw new NumberFormatException();
+      throw new NumberFormatException("non terminated number: " + str);
 
     int max = MAX_VALUE / radix;
     // We can't directly write `max = (MAX_VALUE + 1) / radix'.
@@ -760,12 +760,12 @@
     while (index < len)
       {
        if (val < 0 || val > max)
-         throw new NumberFormatException();
+         throw new NumberFormatException("number overflow (pos=" + index + ") 
: " + str);
 
         ch = Character.digit(str.charAt(index++), radix);
         val = val * radix + ch;
         if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
-          throw new NumberFormatException();
+          throw new NumberFormatException("invalid character at position " + 
index + " in " + str);
       }
     return isNeg ? -val : val;
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]