title: Is throwing an exception a legal else statement?
body: <p>I am currently despairing over a supposedly simple task.</p>
  <pre><code>        protected Entry&lt;K, V&gt;[] entries;
  
  
          public V getOrThrow(K k) throws UnknownKeyException
          {
              for(Entry&lt;K, V&gt; i : entries)
              {
                  if(i.getValue() != null)
                  {
                      if(i.getKey().equals(k))
                      {
                          return i.getValue();
                      }
                      else throw new UnknownKeyException();
                  }
                  else throw new UnknownKeyException();
                  
              }
              
          }
  </code></pre>
  <p>This method should check whether a value exists, then whether the associated key matches the passed parameter and then return the value. Otherwise, an exception is to be thrown. The value is of the type V. Now I get the error: &quot;This method must return a result of type V&quot;. So I suppose not every case of the if statement is covered. Is this because of the exceptions? Are exceptions even legal else statements? Or what else could it be? Thanks a lot in advance!</p>