title: C++ : Catch a divide by zero error
body: <p>Here is a simple piece of code where a division by zero occurs. I'm trying to catch it :</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main(int argc, char *argv[]) {
      int Dividend = 10;
      int Divisor = 0;
  
      try {
          std::cout &lt;&lt; Dividend / Divisor;
      } catch(...) {
          std::cout &lt;&lt; "Error.";
      }
      return 0;
  }
  </code></pre>
  
  <p>But the application crashes anyway (even though I put the option <code>-fexceptions</code> of <em>MinGW</em>).</p>
  
  <p>Is it possible to catch such an exception (which I understand is not a C++ exception, but a FPU exception) ?</p>
  
  <p>I'm aware that I could check for the divisor <strong>before</strong> dividing, but I made the assumption that, because a division by zero is rare (at least in my app), it would be more efficient to try dividing (and catching the error if it occurs) than testing each time the divisor before dividing. </p>
  
  <p>I'm doing these tests on a WindowsXP computer, but would like to make it cross platform.</p>