Say I have the following block of code somewhere:
while(condition){
try {
String twoStr= JOptionPane.showInputDialog("Enter two words sep by a space.");
\\do stuff like splitting and taking an index which may cause out of bound exception
catch (IOException e) {
System.out.println("Sorry your words are terrible.");
}
\\do stuff with twoStr
I cannot access string outside of the try/catch statement, but I don't want to prompt the user to enter another two words in case he messes up and enters a single word. How can I access this value that was initialized in the try block?