title: How to throw std::invalid_argument error?
body: <p>I have an overloaded operator in my <code>Fraction</code> class in C++ which is designed to take input from standard input in the form of an integer over an integer i.e. <code>1/2</code> or <code>32/4</code> and initialize a <code>Fraction</code> object based off of those values. It works, but I'm having trouble catching errors.</p>
  
  <pre><code>// gets input from standard input in the form of (hopefully) int/int
  std::istream&amp; operator &gt;&gt;(std::istream&amp; inputStream, Fraction&amp; frac)
  {
      int inputNumerator, inputDenominator;
      char slash;
  
      if ((std::cin &gt;&gt; inputNumerator &gt;&gt; slash &gt;&gt; inputDenominator) &amp;&amp; slash == '/')
      {
          if (inputDenominator == 0)
          {
              std::cout &lt;&lt; "Denominator must not be 0." &lt;&lt; std::endl;
              throw std::invalid_argument("Denominator must not be 0.");
          }
          frac.numerator = inputNumerator;
          frac.denominator = inputDenominator;
  
          frac.reduce();
      }
      else
      {
          throw std::invalid_argument("Invalid syntax.");
      }
  
  
  
      return inputStream;
  }
  </code></pre>
  
  <p>I invoke the method like this:</p>
  
  <pre><code> Fraction frac(1, 2);
  
  
  while (true)
  {
      try {
          std::cout &lt;&lt; "Enter a fraction in the form int/int: ";
          std::cin &gt;&gt; frac;
          std::cout &lt;&lt; frac;
      } catch (std::invalid_argument iaex) {
          std::cout &lt;&lt; "Caught an error!" &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>But whenever an error is thrown, (I'll enter something like <code>garbage</code>) this causes the loop to go on forever without asking for input. What is the reason for this?</p>