Forum Stats

  • 3,826,772 Users
  • 2,260,706 Discussions
  • 7,897,072 Comments

Discussions

Exception Handling in Method References

md.nawazish.khan-JavaNet
md.nawazish.khan-JavaNet Member Posts: 5
edited Dec 7, 2015 4:32PM in Java 8 Questions

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

     }    

}

Tagged:

Answers

  • Unknown
    edited Dec 7, 2015 4:32PM
    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:
    

    Sorry - but that 'pseudo-code' doesn't demonstrate anything at all. You can't construct threads like that for one.

    Post ACTUAL code that you are having the issue with so we can see what you are talking about.