• 使用throw抛出年龄异常


    package com.oned9z;
    /**
    * @program: com.oned9z
    * @description:使用throw抛出年龄异常
    * @author: Mr.Lin
    * @create: 2019年7月23日
    **/
    public class Person {
    private int age;

    public int getAge() {
    return age;
    }

    public void setAge(int age) throws Exception{
    if(age>=1 && age<=100){
    this.age = age;
    }else{
    throw new Exception("年龄必须在1—100之间!");
    }

    }

    }

    package com.oned9z;
    /**
    * @program: com.oned9z
    * @description:测试类
    * @author: Mr.Lin
    * @create: 2019年7月23日
    **/
    public class TestAge {
    public static void main(String[] args) {
    Person person = new Person();
    try{
    person.setAge(1231312);
    }catch (Exception e){
    e.printStackTrace();
    }
    }

    }

  • 相关阅读:
    k8s的包管理
    k8s的paas平台
    zookeeper相关
    java之rpc/orm
    java之spring
    EK算法
    SAM学习笔记
    生日悖论不是“悖论”!
    分块--莫队学习粗略预习
    二项式反演学习笔记
  • 原文地址:https://www.cnblogs.com/lpbk/p/11233575.html
Copyright © 2020-2023  润新知