I have this method that returns a Recipe object if found by name in my Menu array. If it doesnt find it, it throws a custom RecipeNotFoundException and just says it isnt found...
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;
}
Under its current condition it only checks the first Menu spot, how do I make it check all of them before throwing the exception!? I've tried inverting and floping but it just leads to NullPointerExceptions and checking the whole thing without being able to do the throwing. Any one got some guidance? Thanks in advance!