I've been doing some pure Java development recently, and I'm using an external lib that exposes a small number of methods, each of which have the possibility of throwing an Exception
.
Eclipse won't let me compile my program unless I wrap each of those calls in a try-catch
block. So far, no big deal.
Then I noticed some things, like ArrayList.add()
, which throws IndexOutOfBoundsException
. How is it that I can call something like this without needing to wrap it in a try..catch
? Obv, in this particular case, it would be incredibly irritating if you had to do it each time, but how and why is try-catch
enforced in some situations, but not others?