I am out of curiosity about my code. I used a setter which includes throw exception for a class, and used a try-catch box inside the test class. I am not sure whether the throw part works well (does it work right?)or should I add 'throws'before 'if'statement, and I want to know what I should do to make it more effecient. These are my codes. Thank you for reading my question.
//setter of the IceCream class, and the setter includes throw exception
public void setFlavor(int t){
if(//code)
{
}
else{
throw new IllegalArgumentException(toString());
}
//testing class
try{
IceCream ice = new IceCream();
p.setFlavor();
}
catch (IllegalArgumentException ex){
System.out.println(ex);
}