title: c++ How do I do exception handling in a while loop to pick up typing errors
body: <p>Im trying to eliminated the infinite loop by using exception handling in my code but its not working can someone take a look at this snippet and tell me what I'm doing wrong?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>void Addition(float num)
   {
    
    cout&lt;&lt;"Please enter number you wish to add:"&lt;&lt;endl;
    cin&gt;&gt;num;
    
    while( num!=-9999)
    {
     Sum+=num;
     cout&lt;&lt;"Sum is:"&lt;&lt;Sum&lt;&lt;endl;
     cout&lt;&lt;"Please enter number or enter -9999 to exit"&lt;&lt;endl;
     try{
      cin&gt;&gt;num;
     }
     catch(...)
     {cout&lt;&lt;"ERROR"&lt;&lt;endl;
     }
    
     
    }
    
    
   }</code></pre>
  </div>
  </div>
  </p>