Method with two exception type parameters

Zdenek Tronicek tronicek at fel.cvut.cz
Mon May 19 01:03:48 PDT 2008


We can declare a method with two exception type parameters:

   static <throws X extends IOException, Y extends InterruptedException>
     void perform({ => void throws X, Y } p) throws X, Y {
         p.invoke();
     }

But how to call it? This does not compile.

   try {
     perform({ => Thread.sleep(100); new FileWriter("x").close(); });
   } catch (IOException | InterruptedException e) {
     System.out.println(e);
   }

However, this compiles:

   try {
     perform({ => Thread.sleep(100); });
   } catch (InterruptedException e) {
     System.out.println(e);
   }

And this not:

   try {
     perform({ => new FileWriter("x").close(); });
   } catch (IOException e) {
     System.out.println(e);
   }


Z.
-- 
Zdenek Tronicek
Department of Computer Science and Engineering
Prague                   tel: +420 2 2435 7410
http://cs.felk.cvut.cz/~tronicek









More information about the closures-dev mailing list