java基础知识-异常

Exception和Error

参考:https://www.cnblogs.com/jtlgb/p/5985120.html
Exception分为运行时异常和非运行时异常。异常处理中不需要关注二者,直接抓Exception。外层再抓Throwable异常。确保无论什么情况,系统运行期间的异常都不会直接抛给用户。

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    try {
        System.out.println(list.get(1));
    } catch (Exception e) {
        e.printStackTrace();
    }catch (Throwable t){
        t.printStackTrace();
    }
}

猜你喜欢

转载自blog.csdn.net/yulong1026/article/details/80052860