Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: Thumbs up for suppressable exceptions in JDK 1.7 Date: Thu, 29 Sep 2011 23:57:06 +0200 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 29 Sep 2011 21:58:44 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="AUyBsac4Bvz0HEr1sKU8og"; logging-data="4633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/I9qKWitohtNM7EmwL1d5p" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.23) Gecko/20110920 Thunderbird/3.1.15 In-Reply-To: Cancel-Lock: sha1:cdjxoAkwMir+Rzw0HulnNXeukMA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8404 On 29/09/2011 20:25, Daniel Pitts allegedly wrote: > I want to read up on it, but I wonder if it will help with this > (unfortunate) situation: > > try { > buggyCodeThrowsNullPointerException(); > } catch (Exception oopsThisWasIgnoredByLazyProgrammer) { > throw new BusinessLayerSpecificException( > "Unable to process request for no good reason."); > } > > This suppresses a bug, but the original programmer wasn't thinking about > potential bugs, only recoverable exceptions. The exception is > effectively suppressed. Probably won't help that situation. The suppressed exception mechanism addresses a structural short-coming of the Java core libraries. If at any point you were confronted with two Throwables (and their respective stack of causes), and planned to throw something, you had no choice but to decide to drop one of the two. The situation you're describing here is not a structural problem, it's bad code. Language changes can sometimes facilitate good code or the opposite, but they're not a solution to bad code. The only guaranteed safeguard against bad coding is not coding at all. In other words, while the structural problem could be addressed by a change in the language/libraries, I don't think the one of bad code can. -- DF. Determinism trumps correctness.