首页 > 代码库 > 抛出异常

抛出异常

抛出异常

代码如下:

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;
}

}

抛出异常