title: c++ out of range exception
body: <p>I'm creating a function which iterates through a grid of points and returns the indices of all adjacent points.  For the edge of the grid, there are adjacent points which do not exist, so I have created a few try blocks to handle these cases.  Here is the code:</p>
  
  <pre><code>try {
              all_below[j] = Mesh.matrix[r[i]][c[i] - j];
          }
          catch (const std::out_of_range&amp; oor) {
              below = NAN;
              below_k = NAN;
          }
  </code></pre>
  
  <p>But whenever I try to run the program, the catch statement doesn't catch the exception and the program crashes (because Mesh.matrix is out of range).  What am I doing wrong?</p>
  
  <p>Edit:</p>
  
  <p>matrix is a 2D vector of int.</p>