java - Why is try/catch needed in some cases but not others? -


this question has answer here:

i've been doing pure java development recently, , i'm using external lib exposes small number of methods, each of have possibility of throwing exception.

eclipse won't let me compile program unless wrap each of calls in try-catch block. far, no big deal.

then noticed things, arraylist.add(), throws indexoutofboundsexception. how can call without needing wrap in try..catch? obv, in particular case, incredibly irritating if had each time, how , why try-catch enforced in situations, not others?

unchecked exceptions (subclasses of error or runtimeexception) need no try..catch block, , when there no try...catch, method need not declare throws (you can, of course, , consider declaring throws practice) . on other hand, checked ones need try...catch, or declares throws.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -