title: Try Catch Block in Java
body: <p>So I'm given this code and I have to create an Exception and then use a <code>Try/Catch</code> Block to catch it. I've already made the Exception, at the bottom of the code. But I've never used a <code>Try/Catch</code> Block before and am not sure how to implement it. </p>
  
  <p>The Exception is if a rank that isn't listed under the <code>enum</code> is entered. I need to use a <code>toString</code> with the caught exception as well, but I'm pretty sure I can figure that one out.</p>
  
  <pre><code>package pracapp4;
  
  import java.util.Scanner;
  
  public class Staff extends Employee
  {
  
    enum Title
    {
      DEPARTMENT_HEAD, DIRECTOR, DEAN, VICE_CHANCELLOR, CHANCELLOR
    }
  
    private Title title;
  
    public Staff()
    {
      super();
      title = Title.DEPARTMENT_HEAD;
    }
  
    public Staff(String firstName, String lastName, int salary, Title title)
    {
      super(firstName, lastName, salary);
      this.title = title;
  
    }
  
    @Override
    public String toString()
    {
      return super.toString() + "\n\tTitle: " + title;
    }
  
  
    @Override
    public void display()
    {
  
      System.out.println("&lt;&lt;Staff&gt;&gt;" + this);
  
    }
  
    @Override
    public void input(Scanner in)
    {
      super.input(in);
  
      if (in.hasNext())
      {
        this.title = Enum.valueOf(Title.class, in.next());
      }
    }
  
    class InvalidRankException extends Exception
    {
        public InvalidRankException()
        {
         super ("Unknown Rank Name: ");
  
        }   
    }
  }
  </code></pre>