當(dāng)程序運(yùn)行時(shí),當(dāng)輸入負(fù)數(shù)或字母時(shí),catch 不會(huì)捕獲錯(cuò)誤。否則程序運(yùn)行良好,其他任何事情都沒(méi)有錯(cuò)誤。當(dāng)輸入不正確的輸入時(shí),它只是捕獲未捕獲。 for (int customer=0; customer<numberOfCustomers; customer++) { try { // get amount used by customer as String, convert to double GBused = Double.valueOf(Accounts[customer][USED]); // compute bill based on the customer's plan selection switch (Accounts[customer][SELECTION]) { case "Plan-A": bill = computeBill (GBused, PLAN[A][LIMIT], PLAN[A][PRICE]); break; case "Plan-B": bill = computeBill (GBused, PLAN[B][LIMIT], PLAN[B][PRICE]); break; case "Plan-C": bill = computeBill (GBused, PLAN[C][LIMIT], PLAN[C][PRICE]); break; case "Plan-D": bill = computeBill (GBused, PLAN[D][LIMIT], PLAN[D][PRICE]); break; default: bill = 0.00; break; } // convert the bill to a String and save into the array Accounts[customer][BILL] = String.valueOf(bill); } // end of try catch (NumberFormatException e) { System.out.println ("Values for GB used must be numeric"); }
添加回答
舉報(bào)
0/150
提交
取消