其他分享
首页 > 其他分享> > 异常处理 try catch

异常处理 try catch

作者:互联网

#include <iostream>
using namespace std;

void func(int a)
{
   if(a == 0)
   {
      throw string("a is error");
      throw a;
   }
}

int main()
{
   try
   {
      func(0);
   }
   catch(int a)
   {
      cout << "a " << a << endl;
   }
   catch(const string &s)
   {
      cout << s << endl;
   }

   return 0;
}
$ ./a.out    
a is error

标签:int,try,func,error,catch,异常,throw
来源: https://www.cnblogs.com/zhangxuechao/p/16600771.html