summaryrefslogtreecommitdiffstats
path: root/src/test/test4/MultiCatch.java
blob: 142e3241a9779a88c923608654ed40452af01a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package test4;

public class MultiCatch {
    public void print() { System.out.println("MultiCatch"); }
    public int test1() { return m1(1); }
    public int m1(int i) {
        // Java 7 syntax
        try {
            return foo(i);
        }
        catch (java.io.IOException | NullPointerException e) {
            return e.getMessage().length();
        }
    }
    public int foo(int i) throws java.io.IOException {
        if (i < 0)
            throw new java.io.IOException("negative");
        else if (i < 10)
            throw new NullPointerException("less than 10");
        else
            return i;
    }
}