各コンストラクタにthrows節を配置する必要がありますか、またはスーパークラスに渡される最後のオーバーロードされたコンストラクタだけを配置する必要がありますか?チェーンオーバーロードされたコンストラクタでスロー例外をどこに配置しますか?
//Constructors
public ManufacturedPart(){
this(0, null, 0, 0, 0);
}
public ManufacturedPart(int id){
this(id, null, 0, 0, 0);
}
public ManufacturedPart(int id, double lCost, double mCost){
this(id, null, 0, lCost, mCost);
}
public ManufacturedPart(int id, String desc, double sellPrice, double lCost, double mCost){
super(id, desc, sellPrice);
setLaborCost(lcost);
setMaterialCost(mCost);
}
//Set Labor Cost
public void setLaborCost(double lCost) throws InvalidProductionArgumentException {
if(lCost < 0)
throw(new InvalidProductionArgumentException("Labor cost can't be less than 0"));
else if(lCost >= 0)
laborCost = lCost;
}
//Set Material Cost
public void setMaterialCost(double mCost) throws InvalidProductionArgumentException {
if(mCost < 0)
throw(new InvalidProductionArgumentException("Material cost can't be less than 0"));
else if(mCost >= 0)
materialCost = mCost;
}
あなたのメソッドで呼び出されたメソッドによってスローされたすべての例外は、 'throws'をキャッチまたは追加することによって処理する必要があります。コンストラクタは「特別な」メソッドですが、このルールから除外されるわけではありません。 –