?? trycatchfinally.java
字號:
public class TryCatchFinally
{ public static void main(String args[ ])
{ Method(0);
Method(1);
Method(2);
}
static void Method(int a)
{ System.out.println("調用方法method("+a+")");
try
{ if(a==0)
{ System.out.println("\t沒有異常產生,正常退出");
return;
}
else if(a==1)
{ int i=0;
int j=3/i;
}
else if(a==2)
{ int iArray[ ]=new int[4];
iArray[4]=3;
}
}
catch(ArithmeticException e)
{ System.out.println("\t捕獲異常:"+e.getMessage( ));
}
catch(ArrayIndexOutOfBoundsException e)
{ System.out.println("\t捕獲異常:"+e);
}
catch(Exception e)
{ System.out.println("\t產生的異常已被處理,該 catch 塊不會被執行。");
}
finally
{ System.out.println("\t finally 塊總是被執行的。");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -