Exception和RuntimeException

时间:2014-08-05 11:01:09   收藏:0   阅读:290

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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!