title: Why am I not catching this exception properly?
body: <p>I'm trying to catch an Exception that should show an error message but doesn't seem to be doing so. I have made another block of code that is exactly the same apart from the changes of some variable names and that catches an exception but this one doesn't seem to be doing so.  The purpose of the exception is that the program should look for a Plant object and if it is not found it should throw an exception to show that herbivores only eat plants. Here is the relevant pieces of code:</p>
  
  <p><strong>Main method</strong></p>
  
  <pre><code>import java.util.logging.Level;
  import java.util.logging.Logger;
  
  public class Main {
      public Main() {
          super();
      }
              Rabbit rabbitExample = new Rabbit();
  
  
      public static void main(String[] args) {
  
                  Rabbit rabbitExample = new Rabbit();        
  
                                System.out.println("************EXCEPTION 2************");        
  
          try {            
  
              Food pork = new Food("Prok");
              System.out.println("************Herbivore caught Exception example************");
              System.out.println("Exception caught");
              rabbitExample.eat(pork);
              //wolfExample.eat(vegFood);
  
          } catch (Exception e) {
              // TODO: Add catch code
  
              e.printStackTrace();
          } 
  
          try {     
  
               System.out.println("************Herbivore non-caught Exception example************");
               Food vegiFood = new Plant("Vegetables");    // you create a Meat object and store it in a Food variable (so to speak)
               System.out.println("Herbivores eat " + rabbitExample.eat(vegiFood));   // must be surrounded by a try-catch block
          }
              catch (Exception ex) {
              // TODO: Add catch code
               Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);;
  
      }
  }
  }
  </code></pre>
  
  <p><strong>Animal class</strong></p>
  
  <pre><code>abstract public class Animal 
  {
  
  String name;
  int age;  
  String noise;
  
  abstract public void makeNoise();
  
  public String getName() {
          return name;
      }
  
      public void setName(String newName) {
          name = newName;
      }
  
  abstract public Food eat(Food x) throws Exception;
  
  }
  </code></pre>
  
  <p><strong>Rabbit class</strong></p>
  
  <pre><code>public class Rabbit extends Herbivore
  {
  
      Rabbit()   
  {
      name = "Haryy";
      age = 2;
  }
  
       public void makeNoise()  
      {
          noise = "Squeek!";
      }
      public String getNoise()  
      {
          return noise;
      }
      public String getName() 
      {
          return name;
      }  
      public int getAge()
      {
          return age;
      }
  
      public String eat(String Food)
      {
          return Food;
      }
      public Food eat(Food x) throws Exception
      {
          if (x.equals(new Plant("Meat"))) {
                  throw new Exception("Herbivores only eat plants!");
              } else {
                  return x;
              }   
      }
  }
  </code></pre>
  
  <p><strong>Herbivore class</strong></p>
  
  <pre><code>public class Herbivore extends Animal
  {
  
      public Food eat(Food x) throws Exception
      {
          if (x.equals(new Plant("Meat"))) {
                  throw new Exception("Herbivores only eat plants!");
              } else {
                  return x;
              }
  
      }
  
       public void makeNoise()  
      {
          noise = "Woof!";
      }
      public String getNoise()  
      {
          return noise;
      }  
  }
  </code></pre>
  
  <p><strong>Food class</strong></p>
  
  <pre><code>public class Food {
  
      //field that stores the name of the food
      public String name; 
  
      //constructor that takes the name of the food as an argument
      public Food(String name){
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
      @Override
    public String toString() {
      return name;
    } 
  }
  </code></pre>
  
  <p>I apologist about the amount of code displayed but I wanted to show all relevant code required in order to run the program. The output is as displayed:</p>
  
  <pre><code>************EXCEPTION 2************
  ************Herbivore caught Exception example************
  Exception caught
  ************Herbivore non-caught Exception example************
  Herbivores eat Vegetables
  </code></pre>
  
  <p>Whereas the output should be:</p>
  
  <pre><code>************EXCEPTION 2************
  ************Herbivore caught Exception example************
  Exception caught
  java.lang.Exception: Herbivores only eat plants!
  ************Herbivore non-caught Exception example************
  Herbivores eat Vegetables
  </code></pre>
  
  <p>Any help is appreciated, thanks.</p>