首页 > 其他 > 详细

Exception和RuntimeException

时间:2014-08-05 11:01:09      阅读:289      评论:0      收藏:0      [点我收藏+]

public class RuntimeExceptionDemo01 {
public static void main(String[] args) {
    String string="123";
    int temp=Integer.parseInt(string);
    System.out.println("123*123=: "+temp*temp);
}
}

 

    public static int parseInt(String s) throws NumberFormatException {
    return parseInt(s,10);
    }

为什么main里不需要try catch?:

NumberFormatException extends IllegalArgumentException

IllegalArgumentException extends RuntimeException

RuntimeException extends Exception

可知:

1,Exception在程序中必须使用try。。。catch进行处理。

2,RuntimeException可以不使用try。。。catch进行处理,但如果有异常产生,则异常交由JVM进行处理。

Exception和RuntimeException,布布扣,bubuko.com

Exception和RuntimeException

原文:http://www.cnblogs.com/vonk/p/3891674.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!