4. try … catch … finally 語法
Try
{
}
catch (…)
{
}
finally (…)
{
}
next line of the code
Try
{
}
catch (…)
{
}
finally (…)
{
}
next line of the code
No
exceptions
thrown
An
exception
arises:
11. throw
● 舉例: 開發撰寫一個汽車類別, 設定輪胎個數
public class Car {
private int intTires;
public void setTires(int num){
if (num>4 || num <= 0) throw new
Exception();
else intTires = num;
}
}