fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. interface Task<E extends Exception> {
  11. void run() throws E;
  12.  
  13. static <E extends Exception> void apply(Task<E> task) {
  14. try {
  15. task.run();
  16. } catch (Exception e) {
  17. System.out.println(e.getMessage());
  18. System.out.println("Лови петуха!");
  19. }
  20. }
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. Task.apply(() -> {
  26. throw new Exception("Петх на воле!");
  27. });
  28. }
  29. }
Success #stdin #stdout 0.07s 33680KB
stdin
Standard input is empty
stdout
Петх на воле!
Лови петуха!