title: Catch Segmentation fault in c++
body: <p>Does a <code>try-catch</code> block catch segmentation fault errors?</p>
  
  <p>I am reading a text file using the function given below but sometimes the file is empty and the program crashes. I would like the program to continue running and provide another file when this file is empty or in use.</p>
  
  <pre><code>Path2D read_gesture(const char* filename)
  {
      Path2D path;
      //MultiStrokeGesture MultiStrokes;
  
      vector&lt;string&gt; text_file;
  
      int no_of_paths=0;
      std::ifstream ifs(filename);
  
      for (std::string line; std::getline(ifs, line); )
      {
          no_of_paths=no_of_paths+1;
          double a, b;
          stringstream ss(line);
          if (!(ss &gt;&gt; a &gt;&gt; b)) {cout&lt;&lt;"wrong format"&lt;&lt;endl;}
          std::cout &lt;&lt; "You said, " &lt;&lt; a &lt;&lt; ", " &lt;&lt; b &lt;&lt; ".\n";
          path.push_back(Point2D(a,b));
  
      }
      cout&lt;&lt;"saving gesture"&lt;&lt;endl;
      return path;
  
  
  }
  </code></pre>
  
  <p>I tried something like:</p>
  
  <pre><code>Path2D path;
  try 
  {
      path=read_gesture("test.txt");
  }
  catch(int e)
  {
      path=read_gesture("test2.txt");
  }
  </code></pre>
  
  <p>but the program still crashes. What might the problem be?</p>
  
  <ul>
  <li>A little correction, the file called in <code>catch</code> was not same as that of <code>try</code>, that was a typo.</li>
  </ul>