您的位置:首页 > 编程语言 > C语言/C++

C++ 异常处理:try、catch、throw、异常规格申明

2015-04-09 23:13 639 查看
一、代码

        try、catch、throw

        异常规格申明

1.1 异常规格申明

         void  f()  throw(int)             可以抛出int型异常

        void  f()  throw(char*, E)    可以抛出char*或E型异常

        void  f()  throw()                 不可以抛出任何异常

        void  f()                                可以抛出任何异常

        void  f() t hrow(...)             可以抛出任何异常,比不写更好

1.2 代码

#include <iostream>
using namespace std;

//try、catch、throw

//void f(void) throw(int)
void f(void) throw() //意外异常
{
//
throw 1;
}

int main(int argc, char* argv[])
{
//
try
{
f();
}
catch(int) //
{
cout<<"int exception"<<endl;
}

return 0;
}
二、输出结果

        void  f(void)  throw(int) :



        void  f(void)  throw() :

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: