Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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