java - Why is try/catch needed in some cases but not others? -
this question has answer here:
- checked vs unchecked exception 4 answers
- java: checked vs unchecked exception explanation 18 answers
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
Post a Comment