title: How to catch an exception in Java?
body: <p>How to catch an exception in Java? I have a program that accepts user input which is of integer value. Now if the user enters an invalid value, it throws a <code>java.lang.NumberFormatException</code>. How do I catch that exception?</p>
  
  <pre><code>    public void actionPerformed(ActionEvent e) {
          String str;
          int no;
          if (e.getSource() == bb) {
              str = JOptionPane.showInputDialog("Enter quantity");
              no = Integer.parseInt(str);
   ...
  </code></pre>