0

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";
   }
 }
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by gcardonav
0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.