码迷,mamicode.com
首页 > 其他好文 > 详细

自定义异常

时间:2019-08-06 00:39:17      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:super   pre   col   throw   new   bounds   this   exce   throws   

自定义异常就为了一个名字而已

public void setAge(int age) throws AgeOutOfBoundsException {
        if (age > 0 && age <120) {
            this.age = age;
        } else {
            throw new AgeOutOfBoundsException("年龄非法");
        }
        
    }
    
}
class AgeOutOfBoundsException extends Exception{
    public AgeOutOfBoundsException(String dec) {
        super(dec);
        
    }
    
}

 

自定义异常

标签:super   pre   col   throw   new   bounds   this   exce   throws   

原文地址:https://www.cnblogs.com/yaobiluo/p/11306492.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!