嵌套的Try-Catch块--------异常处理(3)
生活随笔
收集整理的這篇文章主要介紹了
嵌套的Try-Catch块--------异常处理(3)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
當(dāng)有一個Try塊沒有一個對應(yīng)的異??商幚?#xff0c;則其父類的異常處理機制去處理。如果父類的異常處理機制不能處理,則java run-time system將會拋出一個異常。
例子:
class Nest{public static void main(String args[]){//Parent try blocktry{//Child try block1try{System.out.println("Inside block1");int b =45/0;System.out.println(b);}catch(ArithmeticException e1){System.out.println("Exception: e1");}//Child try block2try{System.out.println("Inside block2");int b =45/0;System.out.println(b);}catch(ArrayIndexOutOfBoundsException e2){System.out.println("Exception: e2");}System.out.println("Just other statement");}catch(ArithmeticException e3){System.out.println("Arithmetic Exception");System.out.println("Inside parent try catch block");}catch(ArrayIndexOutOfBoundsException e4){System.out.println("ArrayIndexOutOfBoundsException");System.out.println("Inside parent try catch block");}catch(Exception e5){System.out.println("Exception");System.out.println("Inside parent try catch block");}System.out.println("Next statement..");} }輸出: Inside block1 Exception: e1 Inside block2 Arithmetic Exception Inside parent try catch block Next statement..
轉(zhuǎn)載于:https://www.cnblogs.com/yandufeng/p/5009626.html
總結(jié)
以上是生活随笔為你收集整理的嵌套的Try-Catch块--------异常处理(3)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Javascript操作DOM常用API
- 下一篇: Codeforces 603A Alte