Code:
1#include <iostream>
  2 #include <string>
  3 
  4 using namespace std;
  5 
  6 class Matherror
  7 {
  8 private:
  9         string error_mes;
 10 public:
 11         Matherror (const string error)
 12         {
 13                 error_mes=error;
 14         }
 15 
 16         string &  what ()
 17         {
 18                 return error_mes;
 19         }
 20 
 21 };
 22 
 23 int main ()
 24 {
 25         int x,y;
 26 
 27         try
 28         {
 29                 cout << "please input two intergrator : x= y= " << endl;
 30 
 31                 cin >> x >> y;
 32 
 33 
 34                 if (y==0)
 35                         throw Matherror ("derive by zero!");
 36 
 37                 else if (!cin.good ())
 38                         throw string ("one of the input is not integer");
 39 
 40                 throw (1);
 41 
 42         }
 43 
 44         catch (Matherror s) {cerr << s.what () << endl;}
 45         catch (string str) {cerr << str << endl;}
 46         catch (...) {cout << x%y << endl;}
 47         return 0;
48 }
Hi everyone
The string "one of the input is not integer" should be outputted when characters are entered.Howerver, the "derive by zero!" is outputted when characters are entered, so it seems !cin.good () does not work. what is wrong?

Fan Li