一个关于C++异常的疑惑!!!~~~
下面代码:
#include "stdafx.h"#include "iostream"#include "exception"using std::exception;using std::cin;using std::cout;using std::endl;int hmean(int a,int b);int _tmain(int argc, _TCHAR* argv[]){ int x,y,z; cout<<"Enter two numbers :"; while(cin>>x>>y&& x!=0&&y!=0) { try { z = hmean(x,y); } catch(exception e) { cout<<e.what()<<endl; cout<<"Enter a new pair of numbes: "; continue; } std::cout<<"Harmonic nean of "<<x<<" and "<<y <<" is "<<z<<endl; cout<<"Entre next set of numbers <0 0to quit>: "; } return 0;}int hmean(int a,int b) throw (exception ){ cout<<" 抓不住!~~~~"<<endl; return 2*a*b/(a+b); //分母为零时会抛异常}