Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Holy boop: goto for Java Date: Mon, 04 Jun 2012 20:31:30 +0200 Lines: 55 Message-ID: References: <6AVyr.1859$8l2.827@newsfe14.iad> <9hrps7h7fnsv1etndoklmq4h4r1dnke6kv@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net cAIumemsgDFSbJ3UAt9PLQsPzZAOLFzzLudlds7aUymeEUhcpbd73ntUoCuyrtB2g= Cancel-Lock: sha1:jQGgI+NgKlX1V9j2CopHE5sRd4U= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:15057 On 04.06.2012 19:45, Lew wrote: > public void processResources(String ... resourceNames) > { ... I'd rather public void processResources(String ... resourceNames) { for (String name : resourceNames) { try { final BufferedReader br = new BufferedReader(new FileReader(name)); try { doSomething(br); reportComplete(name); } catch(IOException exc) { logger.error("Issue while processing "+ name, exc); } finally { close(br); } } catch(FileNotFoundException exc) { logger.error("Cannot find "+ name, exc); } } } close() is a static helper method which catches IOException and reports it. In other words, I try to place the catch block at the end of a logical section and use try catch to only execute some commands in absence of error. The exception will make the continue superfluous. The advantage in my eyes is that you can easily follow the regular flow and have error handling concentrated in one place. I sometimes even refactor out methods so I can have this catch at the end idiom. In a more realistic example I'd probably extract parts of this into a method (likely the inner try catch finally). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/