try{
// 可能会导致错误的代码
} catch(error){
// 在错误发生时怎么处理
}
#include <iostream>
#include <exception>
using namespace std;
int main () {
try
{
throw 1;
throw "error";
}
catch(char *str)
{
cout << str << endl;
}
catch(int i)
{
cout << i << endl;
}
}
转载:https://blog.csdn.net/xueluowutong/article/details/81257654