【Java】【代码优化】+try catch 异常

参考:Java 代码优化之细节是魔鬼

 

 示例代码

public class test {
    public static void tryCatch(){
        String a = null;
        try {
            System.out.println(a.equals("aa"));
        }catch (Exception e){
            System.out.println("try1");
        }

        try {
            System.out.println(a.equals("aa"));
        }catch (Exception e){
            System.out.println("try2");
        }

        System.out.println(a.equals("aa"));
        System.out.println("aaaaaa");
    }

    public static void main(String[] args) {
        tryCatch();
    }
}
posted @ 2020-05-22 09:38  淡怀  阅读(693)  评论(0编辑  收藏  举报