1
我有這個方法返回一個Recipe對象,如果在我的Menu數組中找到它的話。如果它不找它,它拋出定製RecipeNotFoundException,只是說,它不是發現...在返回一個變量之前檢查數組中的所有位置
public static Recipe getRecipe(String recipeName){
try{
for(int j = 0 ; j < Menu.length ; j++){
if(Menu[j].getName().equals(recipeName)){
return (Recipe)Menu[j];
}
else{
throw new RecipeNotFoundException();
}
}
}catch(RecipeNotFoundException e){
System.out.println("Recipe Not Found!");
}
return null;
}
根據目前的情況只檢查的第一個菜單點,我怎麼讓它扔之前檢查所有的人例外!?我試過反轉和floping,但它只是導致NullPointerExceptions和檢查整個事情,而不能做投擲。任何人得到一些指導?提前致謝!
我甚至不知道你能做到這一點!哦,哇,我感到非常愚蠢,非常感謝你! – Sherifftwinkie 2013-02-13 06:14:49