Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?
Is this a historical accident or intentional? The documentation clearly states two types of exceptions for Double.parseDouble(...)
and one for Integer.parseInt()
, but it seems inconsistent:
Integer.parseInt(null); // throws java.lang.NumberFormatException: null
However
Double.parseDouble(null); // throws java.lang.NullPointerException
double
primitive docs.oracle.com/javase/tutorial/java/nutsandbolts/… – HermeneuticsparseDouble
does not do a null check, and just throws an NPE when it is encountered, but inparseInt
, then input string is checked fornull
. I can't see any good reason why they should behave different. – Lateritious