#includeusing namespace std; double fuc(double x, double y) //定义函数 { if (y == 0) { throw y; //除数为0,抛出异常 } return x / y; } int main() { double res; double x, y; cin >> x >> y; try //定义异常 { res=fuc(x, y); cout << res << endl; } catch (double) //捕获并处理异常 { cerr << "error of dividing zero.n"; //exit(1); //异常退出程序 } system("pause"); return 0; }



