fork download
  1. import java.util.concurrent.Callable;
  2.  
  3. class Main {
  4. public static void main (String[] args) throws MojoFailureException {
  5. new Main().foo();
  6. }
  7.  
  8. void foo() throws MojoFailureException {
  9. execCode(() -> doBar());
  10. execCode(() -> { doBar(); });
  11. //execCode(this::doBar);
  12. }
  13.  
  14. void doBar() throws Exception {
  15. System.out.println("bar");
  16. }
  17.  
  18. void execCode(Runnable code) throws MojoFailureException {
  19. try {
  20. code.run() ;
  21. } catch(Exception e) {
  22. throw new MojoFailureException(e);
  23. }
  24. }
  25.  
  26. class MojoFailureException extends Exception {
  27. MojoFailureException(Exception e) {
  28. super(e);
  29. }
  30. }
  31. }
  32.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: unreported exception Exception; must be caught or declared to be thrown
        execCode(() -> doBar());
                            ^
Main.java:10: error: unreported exception Exception; must be caught or declared to be thrown
        execCode(() -> { doBar(); });
                              ^
2 errors
stdout
Standard output is empty