调用可能抛出异常的函数
(1)java看是否是受检异常,如果是必须try catch, 如果是非受检异常,则不用 try catch
void test()throws MyException;
(2)c++不必try catch,不会编译错误:
void fun (); // 能抛出任何类型的异常
throw; 抛出的异常,catch(...)也捕获不了。
#include <iostream>
class Exception{};
using namespace std;
void test(){
cout<<"call test"<<endl;
throw 1; //如果是throw:则捕获不了,如果是1可以捕获
}
int main(){
try{
try{
test();
}catch(...){
cout<<"exception"<<endl;
throw;
}
}catch(...){
cout<<"reach here";
}
}
原文:http://blog.csdn.net/jiafu1115/article/details/19337625