You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiCatch.java 628B

1234567891011121314151617181920212223
  1. package test4;
  2. public class MultiCatch {
  3. public void print() { System.out.println("MultiCatch"); }
  4. public int test1() { return m1(1); }
  5. public int m1(int i) {
  6. // Java 7 syntax
  7. try {
  8. return foo(i);
  9. }
  10. catch (java.io.IOException | NullPointerException e) {
  11. return e.getMessage().length();
  12. }
  13. }
  14. public int foo(int i) throws java.io.IOException {
  15. if (i < 0)
  16. throw new java.io.IOException("negative");
  17. else if (i < 10)
  18. throw new NullPointerException("less than 10");
  19. else
  20. return i;
  21. }
  22. }