首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个关于C++错误的疑惑!

2012-04-09 
一个关于C++异常的疑惑!!!~~~下面代码:C/C++ code#include stdafx.h#include iostream#include excep

一个关于C++异常的疑惑!!!~~~
下面代码:

C/C++ code
#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);  //分母为零时会抛异常}


想问 是不是在C++中不将异常throw 就不会抓住呢?
因为在这个程序中是抓不住的!~

[解决办法]
谁说C++中1/0时会抛异常?

热点排行