A few notes about the exception

Exception log details expression in Java

package Day20;/*
 *@author wanghongyuan
 *@Create 2020/12/30 7:20
 */

import java.util.List;

public class Demo01Try {
    
    
    public static void main(String[] args) {
    
    
        /*
            1.多次异常分多次处理
            2.多次异常一次捕获,多次处理
            3.多个异常一次捕获,一次处理

         */
        // 多个异常多次处理
            /*try {
                int[] arr = {1,2,3};
                System.out.println(arr[3]);
            }catch (Exception e){
                System.out.println(e);
            }
            try {
                List<Integer> in = List.of(1, 2, 3);
                System.out.println(in.get(3));
            }catch (Exception e){
                System.out.println(e);
            }*/
        //多个异常一次捕获,多次处理
        try {
    
    
            int[] arr = {
    
    1,2,3};
            System.out.println(arr[3]);
            List<Integer> in = List.of(1, 2, 3);
            System.out.println(in.get(3));
        }catch (ArrayIndexOutOfBoundsException e){
    
    
            e.printStackTrace();
        } catch (IndexOutOfBoundsException e){
    
    
            e.printStackTrace();//最详细的报错信息提示及打印
        }
        System.out.println("后续代码");

//        多个异常一次捕获,一次处理
       /* try {
            int[] arr = {1,2,3};
            System.out.println(arr[3]);
//            List<Integer> in = List.of(1, 2, 3);
//            System.out.println(in.get(3));
        }catch (Exception e){
            System.out.println(e);
        }*/

            //System.out.println(e.getMessage());最简洁的报错信息提示及打印
            //System.out.println(e.toString());较详细的报错信息提示及打印


    }
}


Guess you like

Origin blog.csdn.net/weixin_41977380/article/details/111940980