抛出异常

抛出异常

代码如下:

package Day09; public class TestIntSubClass extends TestInt {
public static void main(String[] args) {
int num = Integer.MAX_VALUE;
TestIntSubClass aa = new TestIntSubClass();
System.out.println(num);
try {
num = aa.intAddOne(num);
} catch (Exception e) {
System.out.println(e.getMessage());
} catch (MyException e) {
System.out.println(e.getMessage());
}
System.out.print(num);
} @Override
public int intAddOne(int number) throws Exception {
if (number >= Integer.MAX_VALUE) {
throw new MyException();
}
return ++number;
}

}

posted @ 2017-06-20 19:44  辰峰  阅读(183)  评论(0编辑  收藏  举报