输出异常

异常处理——抛出异常

代码如下:

package Day09;

public class TestInt { public static void main(String[] args) {
int num = Integer.MAX_VALUE-1;
System.out.println(num);
try {
num = intAddOne(num);
} catch (Exception e) {
e.printStackTrace();
}
System.out.print(num);
} private static int intAddOne(int number) throws Exception {
if (number >= Integer.MAX_VALUE) {
throw new Exception("Int max value reached");
}
return ++number;
} }

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