日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

异常注意事项_多异常的捕获处理

發(fā)布時間:2024/4/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 异常注意事项_多异常的捕获处理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
package com.learn.demo03.Exception;import java.util.Arrays; import java.util.List;/*異常的注意事項*/ public class Demo01Exception {public static void main(String[] args) {/*多個異常使用捕獲又該如何處理呢?1. 多個異常分別處理。2. 多個異常一次捕獲,多次處理。3. 多個異常一次捕獲一次處理。*///1. 多個異常分別處理。/* try {int[] arr = {1,2,3};System.out.println(arr[3]);//ArrayIndexOutOfBoundsException: 3}catch (ArrayIndexOutOfBoundsException e){System.out.println(e);}try{List<Integer> list = List.of(1, 2, 3);System.out.println(list.get(3));//IndexOutOfBoundsException: Index 3 out-of-bounds for length 3}catch (IndexOutOfBoundsException e){System.out.println(e);}*///2. 多個異常一次捕獲,多次處理。/*try {int[] arr = {1,2,3};//System.out.println(arr[3]);//ArrayIndexOutOfBoundsException: 3List<Integer> list = List.of(1, 2, 3);System.out.println(list.get(3));//IndexOutOfBoundsException: Index 3 out-of-bounds for length 3}catch (ArrayIndexOutOfBoundsException e){System.out.println(e);}catch (IndexOutOfBoundsException e){System.out.println(e);}*//*一個try多個catch注意事項:catch里邊定義的異常變量,如果有子父類關系,那么子類的異常變量必須寫在上邊,否則就會報錯ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException*//*try {int[] arr = {1,2,3};//System.out.println(arr[3]);//ArrayIndexOutOfBoundsException: 3List<Integer> list = List.of(1, 2, 3);System.out.println(list.get(3));//IndexOutOfBoundsException: Index 3 out-of-bounds for length 3}catch (IndexOutOfBoundsException e){System.out.println(e);}catch (ArrayIndexOutOfBoundsException e){System.out.println(e);}*///3. 多個異常一次捕獲一次處理。/*try {int[] arr = {1,2,3};//System.out.println(arr[3]);//ArrayIndexOutOfBoundsException: 3List<Integer> list = List.of(1, 2, 3);System.out.println(list.get(3));//IndexOutOfBoundsException: Index 3 out-of-bounds for length 3}catch (Exception e){System.out.println(e);}*///運行時異常被拋出可以不處理。即不捕獲也不聲明拋出。//默認給虛擬機處理,終止程序,什么時候不拋出運行時異常了,在來繼續(xù)執(zhí)行程序int[] arr = {1,2,3};System.out.println(arr[3]);//ArrayIndexOutOfBoundsException: 3List<Integer> list = Arrays.asList(1,2,3);System.out.println(list);System.out.println(list.get(3));//IndexOutOfBoundsException: Index 3 out-of-bounds for length 3System.out.println("后續(xù)代碼!");} }

?

總結

以上是生活随笔為你收集整理的异常注意事项_多异常的捕获处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。