标签:stream || end secure out pre lan person hat
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
//系统提供标准异常
#include <stdexcept>
using namespace std;
class Person
{
public:
Person(string name, int age) {
this->m_Name = name;
if (age < 0 || age>200)
{
//抛出越界异常
//throw
//throw out_of_range("年龄越界!");
throw length_error("长度");
}
}
string m_Name;
int m_Age;
};
void test01()
{
try
{
Person p("小赵", 300);
}
catch (out_of_range &e)
{
cout << e.what() << endl;
}
catch (length_error &e)
{
cout << e.what() << endl;
}
}
int main()
{
test01();
return 0;
}
标签:stream || end secure out pre lan person hat
原文地址:https://www.cnblogs.com/lodger47/p/14705730.html