java - Javac doesn't complain on not-catching exception (Runtime Exception) -
i have in class:
/* parses value out of string */ public static int parsevalue(final string text) throws numberformatexception { string cleanedvalue = text.replace("-", "").replace(",", "."); return math.round(float.parsefloat(cleanedvalue) * 100); } for reason javac doesn't complain don't catch numberformatexception in calling code.
can tell me why is?
from java docs, numberformatexception is,
thrown indicate application has attempted convert string 1 of numeric types, string not have appropriate format.
just @ inheritance structure, numberformatexception derives runtimeexception, compiler doesn't force catch exceptions. it's not recommended. need catch/declare checked exceptions.
java.lang.object java.lang.throwable java.lang.exception java.lang.runtimeexception java.lang.illegalargumentexception java.lang.numberformatexception now, method is not required declare in throws clause subclasses of runtimeexception might thrown during execution of method not caught.
Comments
Post a Comment