exception question help!!!

When I compile/run this code, I get an error message. Is this an execution error?
Also, my guess about the problem in this code is that due to catch(int i)
especially because 2./4 does not return an int value. Am i right?
The code works well when I replace catch( int i ) to catch (double i)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 #include <iostream>
    #include <exception>
    
    using namespace std;
    
    int main() {
        try {
            throw 2./4;
        }
        catch(int i) {
            cout << i;
        }
        return 0;
    }
I don't know much about exceptions but I think the data type that you can throw in this case has to be an integer?

you seem to be doing a float number divided by an integer number also.

throw 2./4;

The code you have works fine if you change the number to an integer.
Last edited on
Topic archived. No new replies allowed.