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


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

checked exception thrown from an initializer ok?

From Andreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject checked exception thrown from an initializer ok?
Date 2015-01-13 22:40 +0000
Organization A noiseless patient Spider
Message-ID <slrnmbb7o5.uoi.avl@login.logic.tuwien.ac.at> (permalink)

Show all headers | View raw


I just stumbled into a surprise and I can't tell yet, whether
to be relieved or worried...

To avoid some unneccessary verbosity lateron, I defined in a
central class:
  public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");

What surprises me is, that eclipse accepts it without barfing
about the unhandled exception.  I'd have expected a compiler 
error, and someone on stackoverflow.com apparently even got
one back in '09, because he asked for aesthetically pleasing
workarounds:
( http://stackoverflow.com/questions/1866770/how-to-handle-a-static-final-field-initializer-that-throws-checked-exception )

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...

Back to comp.lang.java.programmer | Previous | Next — Next 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