title: Throwing an std::out_of_range exception C++
body: <p>I have the following code below:</p>
  
  <pre><code>template &lt;typename X&gt;
  const X&amp; ArrayList&lt;X&gt;::at(unsigned int index) const
  {
      try {
         return data[index]; //return the value of the index from the array    
      }
      catch (std::out_of_range outofrange) { //if the index is out of range
         std::cout &lt;&lt; "OUT OF RANGE" &lt;&lt; outofrange.what(); //throw this exception
      }
  }
  </code></pre>
  
  <p>So if i have an array with values </p>
  
  <pre><code>a = [1,2,3]
  a.at(5);
  </code></pre>
  
  <p>should throw an exception "OUT OF RANGE" but it spits out the value 0. I'm not sure what's going on.</p>