java自定义异常抛出
public class HelloWorld {
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");
}
}
本文展示了一个Java自定义异常的实例,通过在程序中抛出自定义异常并捕获,展示了异常处理的基本流程。该示例包括try-catch-finally语句块的使用,以及在异常被捕获后如何进行相应的处理。
384

被折叠的 条评论
为什么被折叠?



