Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Novice Newsgroups: comp.lang.java.programmer Subject: Re: Exception Handling Date: Sun, 11 Mar 2012 20:36:56 +0000 (UTC) Organization: Your Company Lines: 41 Message-ID: References: NNTP-Posting-Host: e/7k2xPBpzXEhFbqYoZT4A.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: Xnews/5.04.25 X-Antivirus-Status: Clean X-Notice: Filtered by postfilter v. 0.8.2 X-Antivirus: avast! (VPS 120311-0, 2012-03-11), Outbound message Xref: csiph.com comp.lang.java.programmer:12872 Lew wrote in news:jjiorj$l5q$2@news.albasani.net: > Novice wrote: >> Lew wrote: >>> Novice wrote: >>> [snip] >>>> I have a utility class called LocalizationUtils which basically >>>> houses convenience methods dealing with i18n/l10n. One of its >>>> methods is getResources(). It expects two parameters, a String >>>> representing the "base name" (the leading part of the resource file >>>> name) and a locale. >>>> >>>> Here's the code for getResources() with all comments and error >>>> handling (aside from the empty catch block) stripped out: >>>> >>>> ==================================================================== >>>> static public ResourceBundle getResources(String baseName, Locale >>>> locale { >>>> ResourceBundle locList = null; >>> >>> Don't use throwaway initializations, usually. >>> >> Why? >> >> If I omit that line and simply use the following in the try block: >> >> ResourceBundle locList = ResourceBundle.getBundle(baseName, locale); >> >> locList isn't visible after the try/catch so that I can return it. > > Well, I didn't recommend that either. There are so many ways to avoid > redundant initialization. So - what could avoid the redundant > initialization without the pitfall you cite? > I see that Arivald has answered that already in his contributions to the thread ;-) I'll use one of his approaches. -- Novice