title: Java - Try/Catch - Access variables in try block if successful
body: <p>Say I have the following block of code somewhere:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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?</p>