Exception transparency - lone throws (no checked exceptions)

Peter Levart peter.levart at marand.si
Thu Jun 10 06:37:45 PDT 2010


On 06/10/10, Peter Levart wrote:
> Hello Stephen,
> 
> Interesting proposal. You don't specify what happens if code in a method calls a method with "lone throws" but doesn't catch anything or catches only some exceptions (but not all Throwables). Does the calling method have to declare "lone throws" too?
> 
>       interface Block<T> {
>           public void invoke(T element) throws;
>       }
> 
>       class MyBlock implements Block<String> {
>           public void invoke(String element) throws {
>             new File(element).getCanonicalFile().delete();
>           }
>       }
> 
> 
> void myMethod() { // ?? do we have to declare "lone throws" here? 
>      try {
>          MyBlock b = new MyBlock();
>          b.invoke("C:\README.txt");
>      } catch (SQLException ex) { // will not be thrown from MyBlock.invoke anyway...
>          ...
>      }
> }
> 
> 
> If not, does that mean that "sneaky" thown exceptions can be thrown by such methods?

If yes, then I don't see any difference between "lone throws" declaration and "throws Exception" (or better "throws Throwable") declaration.

> 
> 
> Regards, Peter
> 


More information about the lambda-dev mailing list