Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30705

Re: checked exception thrown from an initializer ok?

From Andreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject Re: checked exception thrown from an initializer ok?
Date 2015-01-14 11:11 +0000
Organization A noiseless patient Spider
Message-ID <slrnmbcjnp.uoi.avl@login.logic.tuwien.ac.at> (permalink)
References <slrnmbb7o5.uoi.avl@login.logic.tuwien.ac.at> <bcf8ea63-90dd-4633-92fd-8441f8832dd3@googlegroups.com>

Show all headers | View raw


Dmitry Davletbaev <ddomgn@gmail.com> wrote:
> On Wednesday, January 14, 2015 at 3:41:20 AM UTC+5, Andreas Leitgeb wrote:
>> To avoid some unneccessary verbosity lateron, I defined in a
>> central class:
>>   public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
>> JLS for Java 7 - §11.2.3 says:
>> " It is a compile-time error if a class variable initializer (§8.3.2)
>> " or static initializer (§8.7) of a named class or interface can throw
>> " a checked exception class. 
>> I guess I should be worried, or hope for an alternative interpretation
>> of this text that didn't yet occur to me...
>
> Andreas,
> as Steven Simpson already noted there is no checked exceptions.

I could have sworn, that some of the relevant exceptions was a subclass of
IOException...

I had some InputStreamReader, that I originally used with "ISO-8859-1", and
that constructor was declared to throw a checked exception that read like
one of those thrown by Charset.forName - maybe that fooled me.

Ok, now I got it, what fooled me:

The constructor InputStreamReader(java.io.InputStream,java.lang.String)
can throw java.io.UnsupportedEncodingException, which is a *checked* one.

The static method Charset.forName(java.lang.String)
can throw java.nio.charset.UnsupportedCharsetException which is *unchecked*

With charset and encoding being almost synonymous (at least in this context),
I just didn't notice the different name.

Thanks (also to Steve,Eric) for pointing out the uncheckedness of the
relevant exceptions :-)

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

checked exception thrown from an initializer ok? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-01-13 22:40 +0000
  Re: checked exception thrown from an initializer ok? Steven Simpson <ss@domain.invalid> - 2015-01-13 22:52 +0000
  Re: checked exception thrown from an initializer ok? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-01-13 18:06 -0500
  Re: checked exception thrown from an initializer ok? Dmitry Davletbaev <ddomgn@gmail.com> - 2015-01-14 01:17 -0800
    Re: checked exception thrown from an initializer ok? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-01-14 11:11 +0000

csiph-web