fork download
  1. /*
  2.  * Exception example.
  3.  */
  4.  
  5. class Foo {
  6. public void brokenFunction()
  7. {
  8. System.out.println("Hello from Foo!");
  9.  
  10. int[] numbers = null;
  11. System.out.println(numbers.length);
  12. }
  13. }
  14.  
  15. class Bar extends Foo {
  16. @Override
  17. public void brokenFunction()
  18. {
  19. System.out.println("Hello from Bar!");
  20.  
  21. int[] numbers = null;
  22. System.out.println(numbers.length);
  23. }
  24.  
  25. public static void main (String[] args) {
  26. try {
  27. new Foo().brokenFunction();
  28. } catch (NullPointerException e) {
  29. System.out.println(e + " was caught in main");
  30. }
  31.  
  32. try {
  33. new Bar().brokenFunction();
  34. } catch (RuntimeException e) {
  35. System.out.println(e + " was caught in main");
  36. }
  37. }
  38. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Hello from Foo!
java.lang.NullPointerException was caught in main
Hello from Bar!
java.lang.NullPointerException was caught in main