Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Java Checked Exception is BAD! Date: Sat, 6 Feb 2016 08:38:23 -0500 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <00ab9f4e-0f06-48ec-9a65-1a150c129a39@googlegroups.com> <8565ac8a-e4e2-4178-b4da-7f3a8ef8069d@googlegroups.com> <4deef389-ea5b-483a-bff5-4e1bdd45de2e@googlegroups.com> <2b736fcd-b72c-49b5-b4b8-9657ecebd51e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 6 Feb 2016 13:35:46 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="28631"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18an7D4WsjhYQAarfOBCvAZ" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: <2b736fcd-b72c-49b5-b4b8-9657ecebd51e@googlegroups.com> Cancel-Lock: sha1:00egVagEP+0YRcm+PE8rAy3XvSA= Xref: csiph.com comp.lang.java.programmer:33623 On 2/5/2016 7:09 PM, boxzou@gmail.com wrote: >[...] > As you said, if a runtime exception is thrown from method1 and method2 does not know how to handle it, method2 does not need to do anything and method3 can still catch that exception and handle it. The developer need know method2 might throw this exception. I am afraid we can not rely on checked exception to document this exception. Why? Suppose we have > > method3 calls method2a and method2b and method2c > method2a calls method1a1 and method1a2 and method1a3 > method2b calls method1b1 and mehtod1b2 and method1b3 > method2c calls method1c1 and mehtod1c2 and method1c3 > and each method1xy throws one exception say Exception1xy > now method3 signature would be > method3(...)throws Exception1a1, Exception1ab, Exception1a3, Exception1b1, Exception1b2, Exception1b3, Exception1c1, Exception1c2, Exception1c3 > > Do you think this will scale? [...] Question: Which of these nine exceptions should *not* be described in the Javadoc? Imagine yourself writing method4(), and writing a call to method3() within it. "Hmmm," you say to yourself, "Can anything go wrong with the method3() call? Is there anything I ought to be aware of, and perhaps try to cope with if it should happen?" What should you do to try to answer your question? Read the Javadoc? Well, no: You've already told us that listing nine things in the throws clause is too much clutter to be considered acceptable, so writing nine entire @throws paragraphs in the Javadoc would be even more clutter, even less acceptable. So, again: How many of these nine exceptions should be Deep Dark Secrets from anyone who might want to call method3()? -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM