On 29/05/2013 11:23 AM, Martin Buchholz wrote:
[+compiler-dev]


On Wed, May 15, 2013 at 1:05 AM, David Holmes <david.hol...@oracle.com>wrote:

On 15/05/2013 3:16 PM, Martin Buchholz wrote:



General purpose library code sometimes would like to rethrow an
exception that was previously caught.
How should it do that?


Umm catch it and throw it. If it is a checked-exception that you want to
propogate then you should have declared it on your method, else you are
going to wrap it in a runtime exception or error. There is no need for such
sleaze.


Taking a closer look at one use of Thread.stop, I see that we use it to
throw a Throwable out of Callable.call.  Which I think we should be able to
do.  But I can't.

Why do you think you should be able to throw an arbitrary Throwable from Callable.call?

  cat CallableThrow.java && javac CallableThrow.java

public class CallableThrow {
     public static void main(String[] args) throws Throwable {
         final Throwable t = new Throwable();
         new java.util.concurrent.Callable<Void>() {
             public Void call() throws Exception { throw t; }};
     }
}
CallableThrow.java:5: error: unreported exception Throwable; must be caught
or declared to be thrown
             public Void call() throws Exception { throw t; }};
                                                   ^
1 error


If I change Exception to Throwable I get:

public class CallableThrow {
     public static void main(String[] args) throws Throwable {
         final Throwable t = new Throwable();
         new java.util.concurrent.Callable<Void>() {
             public Void call() throws Throwable { throw t; }};
     }
}
CallableThrow.java:5: error: call() in <anonymous CallableThrow$1> cannot
implement call() in Callable
             public Void call() throws Throwable { throw t; }};
                         ^
   overridden method does not throw Throwable
   where V is a type-variable:
     V extends Object declared in interface Callable
1 error

All correct. You can't do this.

David

Reply via email to