c++异常捕获例子

来源:互联网 发布:淘宝公益广告联盟 编辑:程序博客网 时间:2024/05/08 16:05
 15 #include<iostream>
 16 using namespace std;
 17 int main()
 18 {
 19     int i=0,j=0,h=0;
 20     i=100;
 21     int*p=NULL;
 22     try
 23     {
 24         if(p==NULL)throw exception ();
 25         h=*p;
 26     }
 27     catch(...)
 28     {
 29         cout<<"cjj error!"<<endl;
 30     }
 31     return 0;

 32 }

[root@pa137 test]# g++ main.cpp 
[root@pa137 test]# ./a.out 
cjj error!
[root@pa137 test]#