title: overridden method does not throw exception
body: <p>I have a problem when compiling my code, I'm trying to make a method of a class throw an personalized exception, given some conditions. But at the time of compiling I get the message:</p>
  
  <blockquote>
    <p>Overridden method does not throw exception</p>
  </blockquote>
  
  <p>Here's the class and exception declaration:</p>
  
  <pre><code>public class UNGraph implements Graph
  </code></pre>
  
  <p><code>Graph</code> is an interface with all the methods of <code>UNGraph</code> in it (the method <code>getId()</code> doesn't have the <code>throws</code> declaration on that script) </p>
  
  <p>After the constructor I create the exception (inside the class UNGraph): </p>
  
  <pre><code>public class NoSuchElementException extends Exception {
      public NoSuchElementException(String message){
          super(message);
      }
  }
  </code></pre>
  
  <p>Here is the method with the exception</p>
  
  <pre><code>public int getId(....) throws NoSuchElementException {
      if (condition is met) {
          //Do method
          return variable;
      }
      else{
         throw new NoSuchElementException (message);
      }
  }
  </code></pre>
  
  <p>Obviously I don't want the method to throw an exception every time, just when the condition is not met; and when it's met, I want to return a variable.</p>