title: Java program taking input from the command line, with exception handling
body: <p>need help again.  The program is about taking input as age and throwing exception according to the input. It will take the age of the user from the command line as the program runs, the program should handle problems if the user does not input a number on the command line or makes an error in input.</p>
  
  <p>The code I have for this is:</p>
  
  <pre><code> public class Age2 {
  
      public static void main(String args[]){
  
          try{
              int age = Integer.parseInt(args[0]);  //taking in an integer input throws NumberFormat Exception if not an integer
  
              if(age&lt;= 12)
                 System.out.println("You are very young");
  
              else if(age &gt; 12 &amp;&amp; age &lt;= 20)
                 System.out.println("You are a teenager");
  
              else
                  System.out.println("WOW "+age+" is old");
          }
  
          catch(NumberFormatException e){   //is input is not an integer, occurs while parsing the command line input argument
              System.out.println("Your input is not a number");
  
          }catch(ArrayIndexOutOfBoundsException e){ //as takes in input from command line which is stored to a Args array in main, if this array is null implies no input given
              System.out.println("Please enter a number on the command line");
          }
  
      }   
  }//end class
  </code></pre>
  
  <p>The output I'm having:</p>
  
  <p><img src="https://i.stack.imgur.com/jKylq.jpg" alt="Output"></p>
  
  <p>But the program also should show exception if the user makes any mistake like:</p>
  
  <p>"22 22" or "3 kjhk"</p>
  
  <p>see picture below:</p>
  
  <p><img src="https://i.stack.imgur.com/sgkDi.jpg" alt="Not showing any error...."></p>
  
  <p>Could you please help me to modify this?
  Thanks all.</p>