#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdexcept>
class maker {
public:
maker(int age) {
if (age < 0 or age>150) {
throw std::out_of_range("年龄不在范围内\n");
}
else {
this->age = age;
}
}
int age;
};
void test() {
try {
maker m(200);
}
catch (std::out_of_range& ex) {
std::cout << ex.what() << '\n';
}
}
int main(){
test();
return 0;
}
异常的基类与之对应的继承关系
标签:std,int,age,系统,标准,include,异常,maker,out From: https://www.cnblogs.com/lambdaios/p/17966081