title: Correct Exceptions in C++
body: <p>I am just learning how to handle errors in my C++ code.  I wrote this example that looks for a text file called some file, and if its not found will throw an exception.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main()
  {
  int array[90];
  try
  {
     ifstream file;
     file.open("somefile.txt");
     if(!file.good())
      throw 56;
  }
  catch(int e)
  {
      cout&lt;&lt;"Error number "&lt;&lt;e&lt;&lt;endl;
  }
  return 0;
  }
  </code></pre>
  
  <p>Now I have two questions.  First I would like to know if I am using Exceptions correctly.  Second, (assuming the first is true) what is the benefit to using them vs an If else statement?</p>