Is there any way to do this?
//Example function taking in first and last name and returning the last name.
public void lastNameGenerator() throws Exception{
try {
String fullName = JOptionPane.showInputDialog("Enter your full name");
String lastName = fullName.split("\\s+")[1];
catch (IOException e) {
System.out.println("Sorry, please enter your full name separated by a space.")
//Repeat try statement. ie. Ask user for a new string?
}
System.out.println(lastName);
I think I can use scanner for this instead, but I was just curious about if there was a way to repeat the try statement after catching an exception.