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() :
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() :
相关文章推荐
- C++中异常处理的语法 try catch throw
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- C++中异常处理的语法 try catch throw
- C++中异常处理try-throw-catch
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- C++中try_catch_throw的做异常处理用法
- C++ try catch() throw 异常处理
- 异常处理(try catch throw)详解(C++)
- C++异常处理 - try,catch,throw,finally的用法
- C++中的异常处理模块--try, throw, catch总结
- C++中的异常捕获与处理:Try、Throw、Catch关键字的理解和使用
- C++异常处理: try,catch,throw,finally的用法
- C++ try catch() throw 异常处理
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
- c++初级 之 异常处理trycatchthrow
- C++ - 异常处理:try,catch,throw,finally的用法
- C++处理异常技巧-try,catch,throw,finally
- [置顶]C++异常处理:try,catch,throw,finally的用法
- C++中异常处理的语法 try catch throw