0
点赞
收藏
分享

微信扫一扫

Java-自定义异常抛出

yellowone 2023-06-01 阅读 66


public class Test{

    public static void main(String []args) {
       System.out.println("Hello World!");
	
		try{
		exceptiona();
		}catch(Exception e){
			System.out.println(e.getMessage());
			//System.exit(0);//加上这句,finally中的内容就不会运行了
		}finally{
		    System.out.println("结束了");
		}
		
    }

	static void exceptiona() throws Exception{
		throw new Exception("I am you father");
	}

}

System.exit(0); 谨慎使用

举报

相关推荐

Java-自定义注解

0 条评论