title: error catching exception while System.out.print
body: <p>I have 2 classes, one that implements a double lookup( int i);
  and one where I use that lookup(int i) in solving a question, or in this case printing the lookup values. This case is for an array.</p>
  
  <p>So I read the exception documentation or google/textbook and come with the following code:</p>
  
  <pre><code>public double lookup(int i) throws Exception
  {
      if( i &gt; numItems)
          throw new Exception("out of bounds");
      return items[i];        
  }
  </code></pre>
  
  <p>and take it over to my class and try to print my set, where set is a name of the
  object type I define in the class above.</p>
  
  <pre><code>public void print()
  {
      for (int i = 0; i &lt; set.size() - 1; i++)
      {
          System.out.print(set.lookup(i) + ",");
  
      }
      System.out.print(set.lookup(set.size()));
  }
  </code></pre>
  
  <p>I'm using two print()'s to avoid the last "," in the print, but am getting an</p>
  
  <p>unhandled exception Exception (my exception's name was Exception)</p>
  
  <p>I think I have to catch my exception in my print() but cannot find the correct formatting online. Do I have to write </p>
  
  <p>catch exception Exception? because that gives me a syntax error saying invalid type on catch.</p>
  
  <p>Sources like 
  <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/" rel="nofollow">http://docs.oracle.com/javase/tutorial/essential/exceptions/</a> 
  are of little help to me, I'm can't seem to grasp what the text is telling me. I'm also having trouble finding sources with multiple examples where I can actually understand the coding in the examples.</p>
  
  <p>so could anybody give me a source/example for the above catch phrase and perhaps a decent source of examples for new Java programmers? my book is horrendous and I cannot seem to find an understandable example for the above catch phrase online.</p>