Java-自定义异常抛出

yellowone

关注

阅读 66

2023-06-01


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); 谨慎使用

精彩评论(0)

0 0 举报