So, in the documentation for example: java.lang.Integer.parseInt
, I noticed that the code header is:
public static int parseInt(String s) throws NumberFormatException
However, when one has a statement something like int i = Integer.parseInt(someString);
the code compiles fine without a try-catch
block.
Now, on the other hand, if I write a method with the header:
public void connectTo(String ip) throws java.net.HostNotFoundException
and make a call to it without surrounding the call with a proper try-catch
block, the compiler just won't have it. I'm not suggesting that I (or anyone) would want to surround every single Integer.parseInt
call (and others) with a try-catch
block, but I sure am curious as to why the compiler allows it.