Q:

Test cin exception

I'm supposed to test input in a program with exceptions().
I've constructed the following code and I can compile without errors:
cin.exceptions(istream::failbit |istream::badbit);
    do
    {
        try
        {
            getline(cin,uppg);
        }
        catch(istream::failure e)
        {
            cerr << "Exception i inläsning";

        }
        ...
     }while(...)

The thing is.... I dont know how to test this code. What type of input can I write to get a failbit or badbit?

A:

According to this (Error states of streams) failbit generate upon wrong input sequence. For example you write something like: 
int n = 0; cin >> n; and input string instead of number.

    int main(void)
    {
        int n = 0;
        cin.exceptions(istream::failbit | istream::badbit);

        try
        {
            cin >> n;
        }
        catch(istream::failure e)
        {
            cerr << "Exception" << endl;

        }
        return 0;
    }

