私は基本的なプログラミングの試験を準備しています。私は今例外を処理していますが、それをいかに最適に使うかを理解できないようです。私はあなたに最初のコードを与え、次にチェックされた例外を作ることを試みる2番目のコードを与えます。これを入力すると私は感謝しています!例外なしJava、Exception、最良の方法、試験準備
:私の厄介な例外を除いて
public boolean uttak(int species, int kroner, int skilling) {
if (species<=this.species && kroner<=this.kroner && skilling <=this.skilling)
{
this.species -=species;
this.kroner -=kroner;
this.skilling -=skilling;
return true;
}
else return false;
:(その例外に関するトピックの場合)
public void uttak(int species, int kroner, int skilling){
try{
if (species<=this.species && kroner<=this.kroner && skilling <=this.skilling)
{
this.species -=species;
this.kroner -=kroner;
this.skilling -=skilling;
}
}
catch (Exception e){
System.err.println ("Withdrawals can not be done when there is" +
" insufficient money in the machine.");
}
のように、呼び出し元のコードでそれを使用してコードを再フォーマットしてください、それが読めない – aleb2000
してその投稿の私たちはそれについて何も理解できません。 –
例外は、通常のロジックを破壊するものに対してのみ使用する必要があります。それはここにあるのでしょうか? –