C++异常处理机制例子

来源:互联网 发布:oracle hr 数据库 编辑:程序博客网 时间:2024/06/03 23:19

//定义一个异常类

#include<iostream>

using namespace std;

class Cex

      public:

         Cex(){};

         ~Cex(){};

         void msg()

         {

               cout<<"this is error"<<endl;

          }

};

 

void fun()

{

      Cex ex;

      throw  ex;

      int i = 0, j = 90;

      int k = j/i;

}

 

void main()

{

         try

         {

                  fun();

          }

          catch(Cex & e)

          {

                 e.msg;

          }

          catch(...)

          {

                cout<<"unknow"<<endl;

          }

 

 

 

 

 

 

原创粉丝点击