title: java DuplicateKeyException has already been caught
body: <p>I am working with HashMap and am attempting to generate a DuplicateKeyException to prevent overwriting existing keys.</p>
  
  <p>I am trying to throw this exception based on certain user input but am receiving an exception has already been caught error.</p>
  
  <pre><code>try {
    Student student = map.get(uid); // uid is a user defined input.
    if (student != null) { // test for key existence
      key = true;
    } else {
      key = false;
    }
    if (key = true) { // throw duplicate key exception
      throw new DuplicateKeyException();
    } else { // Put new uid into map
      map.put(uid, new Student(name, major));
    }
    JOptionPane.showMessageDialog(null, "It worked...");
  } catch (NullPointerException z) { // If the key doesn't exist
    JOptionPane.showMessageDialog(null, "That record does not exist.");
  } catch (DuplicateKeyException x) { // If the key does exist
    JOptionPane.showMessageDialog(null, "That record already exists.");
  } catch (NumberFormatException y) { // If user input is other than expected
    JOptionPane.showMessageDialog(null, "You must enter integer.");
  }
  </code></pre>
  
  <p>NullPointerException and NumberFormatException are working as expected until DuplicateKeyException is implemented.</p>
  
  <p>"catch DuplicateKeyException()" shows "exception DuplicateKeyException has already been caught."</p>
  
  <p>I have attempted to modify exception order in case they were too broad.  That didn't seem to help the issue.</p>
  
  <p>I'm still new to this and any input is greatly appreciated.</p>