为了账号安全,请及时绑定邮箱和手机立即绑定

自定义异常 以及使用

public class ExceptionTest extends Exception{
	public ExceptionTest(){
		
	}
	public ExceptionTest(String message){
		super(message);
	}
	public void dunkOrNot(int select) throws ExceptionTest{
		if(select==1){
			throw new ExceptionTest("你喝大了");
		}
		else{
			System.out.println("你没喝醉");
		}
	}
	public static void main(String[] args)throws ExceptionTest {
		ExceptionTest et=new ExceptionTest();
		int select=1;
		try{
		et.dunkOrNot(select);
		}
		catch(ExceptionTest e){
			System.out.println("发现异常:"+e.getMessage());
		}
	}
}


正在回答

1 回答


-_-!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java入门第三季
  • 参与学习       409781    人
  • 解答问题       4339    个

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

进入课程

自定义异常 以及使用

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信