1

I often hear advice that catching Throwable or Error is bad practice and Java developer should avoid catching these, I don't know Why?

If language allows you to catch anything which is instance of java.lang.Throwable, then what is the problem of catching them or their subclass java.lang.Error?

If they are bad, shouldn't Java itself has prohibited them from catching?

Please suggest me the answer. Thanks in advance.

Parth Pithadia
  • 276
  • 1
  • 3
  • 18
  • It is not something you should overuse but catching `Throwable` at the highest level of your program (`main` or equivalent) to try to log what happened may be a totally reasonable thing to do... – assylias Jun 16 '15 at 09:12
  • You need to be as specific as possible. Otherwise unforeseen bugs might creep away this way. – codeaholicguy Jun 16 '15 at 09:14
  • 1
    @codeaholicguy Good job copy-pasting the accepted answer of the linked question. – Ingo Bürk Jun 16 '15 at 09:15
  • 2
    You will come across alot of things people say you shouldnt ever do in programming and what they usually mean is 99.9% of the time its bad or you shouldnt do it. Take the infamous "eval is evil" discussion in JavaScript for a perfect example. The JDK doesnt warn or tell you because there are valid use cases for catching "Throwable", they are just uncommon. – ug_ Jun 16 '15 at 09:17

0 Answers0