首页 > 编程语言 > 详细

Java异常处理-手动抛出异常

时间:2020-07-28 01:23:02      阅读:70      评论:0      收藏:0      [点我收藏+]
/**
 * 手动抛出异常
 * throw
 *
 * @author orz
 */
public class ThrowTest {

}
class Student{
    private int id;
    public void regist(int id)
    {
        if(id>0)
        {
            this.id=id;

        }
        else
        {
            throw new RuntimeException("不能为负数");
        }
    }

    public static void main(String[] args) {
        Student s=new Student();
        s.regist(-1);
    }
}

 

Java异常处理-手动抛出异常

原文:https://www.cnblogs.com/orzjiangxiaoyu/p/13388151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!