我只是学习抛出异常,我写了一个代码,但它似乎并不像我可以打印Error: too big
或Error:too large
当我输入10000
或100000
。我该如何解决这个问题才能打印出Error: too big
或Error:too large
。我怎么不能打印出我的抛出异常的错误?
#include<iostream>
#include<stdexcept>
using namespace std;
int main()
{
int xxx;
cout<<"please enter xxx:";
cin>>xxx;
if (xxx==1)
cout<<"2";
else if (xxx==10)
cout<<"3";
else if (xxx==100)
cout<<"4";
else if (xxx==1000)
cout<<"5";
else if (xxx==10000)
throw "too big";
else if (xxx==100000)
throw "too large";
return 0;
}
您添加一个'尝试{}赶上(为const char * MSG){COUT <<味精<< ENDL; }' –