package com.lovecoding.day13.throw01;

public class Person {

    private String name;
    private Integer age;

    public Person(String name, Integer age) {
        if (age < 0){
            //手动抛出异常
            throw new AgeException("年龄不能为负数");
        }

        this.name = name;
        this.age = age;
    }

    public Person() {
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        if (age < 0){
            //手动抛出异常
            throw new AgeException("年龄不能为负数");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
