Multi-catch/final rethrow
Neal Gafter
neal at gafter.com
Fri May 7 17:01:01 PDT 2010
Ulf-
to your 2nd question: Exception is both a supertype and a subtype of
Exception. See JLS 4.10, and note the word "reflexive".
Cheers,
Neal
On Fri, May 7, 2010 at 4:36 PM, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> Howard, Joe,
>
> hm, and what's about my 2nd question ?
>
> -Ulf
>
>
> Am 08.05.2010 01:26, schrieb joe.darcy at oracle.com:
> > If you have a question on what is today legal syntax, your friendly
> > neighborhood java compiler can help you answer that question :-)
> >
> > -Joe
> >
> > On 5/6/2010 12:45 PM, Ulf Zibis wrote:
> >> No answer for my questions? :-(
> >>
> >> -Ulf
> >>
> >>
> >> Am 04.05.2010 11:30, schrieb Ulf Zibis:
> >>> Am 04.05.2010 02:25, schrieb joe.darcy at oracle.com:
> >>>> Greetings,
> >>>>
> >>>> As alluded to as a possibility previously [1], I'm happy to announce
> >>>> that improved exception handling with multi-catch and final rethrow
> >>>> will
> >>>> be part of an upcoming JDK 7 build.
> >>>>
> >>> Great!
> >>>
> >>>> } else {
> >>>> throw (Throwable)new Exception();
> >>>>
> >>> I'm wondering that a cast to a throw is valid syntax, or _in other
> >>> words_, what should such a syntax be good for ???
> >>> In fact, an Exception instance is thrown, and should be caught by catch
> >>> (Exception e). Or not ?
> >>>
> >>>
> >>>> To address this, the third clause is changed to
> >>>>
> >>>>
> >>>>> - is a subtype/supertype of one of the types in the declaration of
> >>>>> the
> >>>>> catch parameter
> >>>>>
> >>> Does that mean, that following variation wouldn't rethrow
> >>> Exception("b3") (and (Throwable)new Exception() too?),
> >>> as it is nor subtype nor supertype of Exception, as it is itself ?
> >>> That IMO would be weird syntax.
> >>>
> >>> class Neg04 {
> >>> static class A extends Exception {}
> >>> static class B extends Exception {}
> >>>
> >>> void test(boolean b1, boolean b2, boolean b3) throws B {
> >>> try {
> >>> if (b1) {
> >>> throw new A();
> >>> } else if (b2) {
> >>> throw new B();
> >>> } else if (b3) {
> >>> throw new Exception("b3");
> >>> } else {
> >>> throw (Throwable)new Exception();
> >>> }
> >>> }
> >>> catch (A e) {}
> >>> catch (final Exception e) {
> >>> throw e;
> >>> }
> >>> catch (Throwable t) {}
> >>> }
> >>> }
> >>>
> >>>
> >>> -Ulf
> >>>
> >>>
> >>>
> >>>
> >>
> >
> >
>
>
>
More information about the coin-dev
mailing list