我想改寫下列getContents方法納入異常處理。特別是,產生一個ArrayIndexOutOfBoundsException時,該方法應該返回值-1.0JAVA嘗試捕捉ArrayIndexOutOfBoundsException異常
public class Four
{
private double [] numbers = {1.0, 2.0, 3.0, 4.0};
public double getContents(int index)
{
return numbers[index];
}
}