title: how to call recursively a method in a try-catch block
body: <p>hi i have this problem i got a method that let a user insert a value representing the "quantity" of a product, now if the quantity wanted by the user is higher then the stock quanity it has to throw an exception and let the user input again the number i tryed it inserting a recursive call of the same method but even if it success it goes in an infinite loop like the exception is still "alive"</p>
  
  <pre><code>...
  try {
      if (!lol2)
          throw new NegativeNumberException(); 
  } catch (NegativeNumberException pto) {
      JOptionPane.showMessageDialog(frame, "Quantità non disponibile");
      this.addToCart(cart,quant);         
  }
  </code></pre>
  
  <p>EDIT i am including now all the code but it's a bit hard so sry for the "complexity" of the code</p>
  
  <p>FULL CODE </p>
  
  <pre><code>public void addToCart(ArrayList&lt;Utilizzabile&gt; cart,ArrayList&lt;Integer&gt; quant) {
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  boolean lol=false;
  Utilizzabile us=null;
  String id = JOptionPane.showInputDialog(frame, "Inserisci un ID prodotto:");
  if (id ==null) { return;}
  while (!id.matches("[0-9]+")) { //user inserts a value and the while checks for an int value inserted
      JOptionPane.showMessageDialog(frame, "Valore inserito errato");
      id = JOptionPane.showInputDialog(frame, "Inserisci un ID prodotto:");
      if (id == null) { return;} }
  int iden = Integer.parseInt(id);
  for (Utilizzabile u: arr) { // this for loop checks if the ID inserted represents a product in the catalog
      if ((u.getId() == iden) &amp;&amp; (u.eAcquistabile())) {
          lol =true;
          us = u; } } 
  if (lol == true) { //now if the ID corresponds to an existent product it ask the user to input the quantity requested
      boolean lol2=false;
      String qua = JOptionPane.showInputDialog(frame, "Inserisci un quantità da aggiungere al carrello:");
      if (qua ==null) { return;}
      while (lol2==false) {
      while (!qua.matches("[0-9]+")) {
          JOptionPane.showMessageDialog(frame, "Valore inserito errato");
          qua = JOptionPane.showInputDialog(frame, "Inserisci un quantità da aggiungere al carrello:");
          if (qua == null) { return;} }
      if (qua.length()&gt;0 &amp;&amp; qua.length()&lt;=8) {
      int quantit = Integer.parseInt(qua);
      for (int l=0;l&lt;cart.size();l++) { //this for checks if in the cart were already that product and then changes the quantities only
          if ((cart.get(l).getId() == us.getId()) &amp;&amp; (us.getRem()-quantit &gt;0) ) {
              int num = quant.get(l)+quantit;
              quant.set(l,num);
              JOptionPane.showMessageDialog(frame, "Quantità del prodotto richiesto aggiornata");
              return;}                
      }
      if ( (us.getRem()-quantit) &gt;0) { //checks if all went good and the quantity is avaiable
              JOptionPane.showMessageDialog(frame, "Prodotto della quantità richiesta aggiunto al carrello");
              lol2=true;
              cart.add(us);
              quant.add(quantit);} }
      try {
          if (lol2==false)
              throw new NegativeNumberException(); }
      catch (NegativeNumberException pto){
          JOptionPane.showMessageDialog(frame, "Quantità non disponibile");
          this.addToCart(cart,quant); }       
      } }
  else {
      JOptionPane.showMessageDialog(frame, "Prodotto non trovato");
      this.addToCart(cart,quant); }       
  </code></pre>
  
  <p>}</p>
  
  <p>this code essentially is a graphical section for let the user add a product to the cart and check is everything is good but i need to place an exception to check if the quantity in stock is less then the quantity wanted by the user (i ve done it without exception with no problems but this is for an exam and i just noticed that the professor wants that i have to solve this problem by using an exception</p>