Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: =?ISO-8859-1?Q?Sven_K=F6hler?= Newsgroups: comp.lang.java.programmer Subject: Re: About java program. Date: Thu, 20 Jun 2013 11:23:12 +0300 Lines: 36 Message-ID: References: <324f929f-772e-4004-81e1-6b454cdae794@googlegroups.com> <19wnriq53qxel.u9rt8wy6z52g.dlg@40tude.net> <1lvu4yv8sxe73$.n4o05ixuag9y.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de erClFVP0FnR1UU7g8WIgrQn6QDHVtJYesuHZ1+Dc8wY26AFxMD5OctCLT4 Cancel-Lock: sha1:jXcOFfa5+I1ShSAXiYJNzkXx7JU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130611 Thunderbird/17.0.6 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:24479 Am 19.06.2013 22:20, schrieb Robert Klemme: > boolean result = false; > try { > result = whatEver() || somethingElse(); > } > catch (whatever...) { > no return or change of result > } I would like to add, that I dislike the initialization of result in this example. If result (for whatever reason) must be declared outside the try-catch block, then please don't initialize it unless you plan on doing something nasty. A nasty example would be that the try block sets result to true midway and an exception in the second half doesn't change the value of result to false for some weired reason. The IMHO cleaner way is the following: boolean result; try { result = whatEver() || somethingElse(); } catch (whatever...) { result = false; } // use result for whatever And may all (ex-)C programmers in this group refrain from telling me that not initializing variables is dangerous. This is Java, where the compiler enforces initialization of variables on all code paths before the first read-access to the variable. Regards, Sven