Multi-catch/final rethrow

Howard Lovatt howard.lovatt at gmail.com
Fri May 7 16:16:33 PDT 2010


 > No answer for my questions?  :-(
 >
 > -Ulf
You might write a method that returns the Throwable:
throw message();
Where message is declared as a Throwable, the most general case, but  
is in fact an Exception. I think the use of cast was only meant to  
illustrate the wider problem.


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


   -- Howard Lovatt +61 419 971 263 (sent from my PDA)


More information about the coin-dev mailing list