Hello

Well I have this coding and I thought I set it up ok to catch this simple exception, but as of right now, the program continues to run after the exception happens and its not even catching it. where did I go wrong. Thank you all

Your rookie programmer

GCard

#include<iostream>
using namespace std;
void main(void)
 {  
  float nNumber1, nNumber2;
  while(1)
   {
    cout << "Enter two integers to get their quotient:";
    try{
      cin >> nNumber1 >> nNumber2;
      if(nNumber2==0) {
        throw(nNumber2);
         }
    }
    catch(int nValue){
     cout << "\nERROR: You tried to divide by"  <<nValue<< "\n";
     return;
    }
    
    cout << "The quotient is:" << (float)nNumber1/nNumber2<< "\n";
   }
 }

the exception thrown is of type float, not int
you have to catch it as a float. catch( float nValue ) { /* ... */ }

the exception thrown is of type float, not int
you have to catch it as a float. catch( float nValue ) { /* ... */ }

Thank you.

This question has already been answered. Start a new discussion instead.