i have this in a class:
/* parses a Value out of a String */
public static int parseValue(final String text) throws NumberFormatException {
String cleanedValue = text.replace("-", "").replace(",", ".");
return Math.round(Float.parseFloat(cleanedValue) * 100);
}
For some reason javac doesn’t complain that i don’t catch the NumberFormatException in the calling code.
Can someone tell me why that is?
From the Java Docs,
NumberFormatExceptionis,Just look at the inheritance structure, NumberFormatException derives from
RuntimeException, which the compiler doesn’t force to catch those exceptions. It’s not recommended. You need to catch/declare only checked exceptions.Now, a method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.