Skip to Main Content

Exception Handling in Method References

md.nawazish.khan-JavaNetDec 7 2015 — edited Dec 7 2015

What is the standard way to handle Exceptions when making a Method Reference when the referenced method declares to throw an exception: Following is the pseudo-code for demonstrating the enquiry:

class Foo{

public static void foo throws Exception{

     throw new Exception("some exception which would propagate up-stack");

}

}

class Bar {

     public void bar(){

     new Thread (Foo::foo).start(); // since Foo.foo declares to throw a checked exception; how should we handle it here? Surrounding this statement in try block on Eclipse does not solve the compiler                                                // complain

     }    

}

Comments
Post Details
Added on Dec 7 2015
1 comment
691 views