#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
int iCom = 0;
try {
cout << "Input a commmand:" << endl;
cin >> iCom;
cout << "The exception command you want is:" << iCom << endl;
if (iCom == 1) {
throw runtime_error("You are asking for an exception!");
}
} catch (runtime_error err) {
cout << err.what() << endl;
}
//throw runtime_error("2: You are asking for an exception!");
#ifndef NDEBUG
if (iCom == 1) {
cerr << "Error: " << __FILE__
<< " : line " << __LINE__ << endl
<< " Compiled on " << __DATE__
<< " at " << __TIME__ << endl;
}
#endif
return 0;
}
C++学习代码--try
最新推荐文章于 2024-05-20 15:29:54 发布