Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12869
| From | Arivald <NOSPAMarivald@interia.pl> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Exception Handling |
| Date | 2012-03-11 20:34 +0100 |
| Organization | Dialog Net |
| Message-ID | <jjiusj$g53$1@news.dialog.net.pl> (permalink) |
| References | <XnsA012D42584994jpnasty@94.75.214.39> <jjh39f$crc$1@news.albasani.net> <XnsA01385245AD09jpnasty@94.75.214.39> |
W dniu 2012-03-11 18:05, Novice pisze:
> Lew<noone@lewscanon.com> wrote innews:jjh39f$crc$1@news.albasani.net:
>
>> > 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.
>
Simplest solution, skip variable at all.
static public ResourceBundle getResources(
String baseName, Locale locale) {
try {
return ResourceBundle.getBundle(baseName, locale);
} catch (MissingResourceException e) {
logger.error('missing resource', e);
return null;
}
}
or, if you need to do something on variable:
try {
ResourceBundle locList = ResourceBundle.getBundle(baseName, locale);
... do something ...
return locList;
} catch (MissingResourceException e) {
logger.error('missing resource', e);
return null;
}
or if you want exception block only for ResourceBundle.getBundle()
ResourceBundle locList; // no null assignment, simply uninitialized
try {
locList = ResourceBundle.getBundle(baseName, locale);
} catch (MissingResourceException e) {
logger.error('missing resource', e);
return null;
}
do something with locList ...
return locList;
--
Arivald
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Exception Handling Novice <novice@example..com> - 2012-03-11 01:51 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-10 18:39 -0800
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-11 11:53 -0300
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-11 10:51 -0700
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-11 16:35 -0300
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 17:05 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-11 10:53 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 20:36 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-11 11:07 -0700
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-11 17:00 -0300
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 22:02 +0000
Re: Exception Handling Arivald <NOSPAMarivald@interia.pl> - 2012-03-11 21:03 +0100
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-11 18:31 -0300
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 21:54 +0000
Re: Exception Handling Patricia Shanahan <pats@acm.org> - 2012-03-11 15:26 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 23:23 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-11 16:52 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-12 17:16 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-13 08:31 -0700
Re: Exception Handling Patricia Shanahan <pats@acm.org> - 2012-03-11 17:51 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-12 17:26 +0000
Re: Exception Handling Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 14:49 -0400
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-11 20:46 -0300
Re: Exception Handling Novice <novice@example..com> - 2012-03-12 17:43 +0000
Re: Exception Handling Patricia Shanahan <pats@acm.org> - 2012-03-11 11:14 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 22:35 +0000
Re: Exception Handling Lew <noone@lewscanon.com> - 2012-03-11 16:58 -0700
Re: Exception Handling Novice <novice@example..com> - 2012-03-12 15:44 +0000
Re: Exception Handling Gene Wirchenko <genew@ocis.net> - 2012-03-12 10:34 -0700
Re: Exception Handling Arivald <NOSPAMarivald@interia.pl> - 2012-03-11 20:34 +0100
Re: Exception Handling Novice <novice@example..com> - 2012-03-11 22:36 +0000
Re: Exception Handling Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 14:41 -0400
Re: Exception Handling Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 14:37 -0400
Re: Exception Handling Novice <novice@example..com> - 2012-03-12 22:43 +0000
Re: Exception Handling Lew <lewbloch@gmail.com> - 2012-03-12 16:11 -0700
Re: Exception Handling Arivald <NOSPAMarivald@interia.pl> - 2012-03-13 00:54 +0100
Re: Exception Handling Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-13 06:05 -0300
csiph-web