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

异常处理 try catch

时间:2022-08-19 08:56:21浏览次数:43  
标签:int try func error catch 异常 throw

#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
From: https://www.cnblogs.com/zhangxuechao/p/16600771.html

相关文章