From a design standpoint, what is the best way to handle illegal input from a user that is defined by the programmer.
Ex: I ask for a user to input quantity, but he inputs “fewfiejfjw”.
Should I make a custom exception? Is there a commonly accepted exception to be thrown in this case? Or should I just say
if(!in.next().matches("\b\d+\b"){
System.out.print("Try again");
//..code to repeat method goes here
}
Thanks for any help.
I don’t think you should throw an exception. You should handle the input and show an error and ask the user to try again. No reason to stop the application.