title: How to set up a try/catch for an integer entered
body: <p>I would like to know how to set up a try/catch on a variable that is a string but has to be checked against an integer like so:</p>
  
  <pre><code>public static void isValidAge(String age) {
      int age2 = Integer.parseInt(age);
      try {
          if(age2 &lt;= 0 || age2 &gt;= 150) {
              throw new NumberFormatException();
          }
      }
      catch (NumberFormatException ex) {
          if(age2 &lt;= 0) {
              System.err.print("Age can not be 0 or negative.");
          }
          else if (age2 &gt;= 150) {
              System.err.print("Age can not be equal to or more than 150.");
          }
          else if (age.contains("#@$")) {
              System.err.print("You did not enter a valid age.");
          }
      }
  }
  </code></pre>
  
  <p>The try/catch must also be able to handle characters and keep the program running still.</p>