java自定义异常抛出

亦凉 2022-05-09 06:50 425阅读 0赞

java自定义异常抛出

  1. public class HelloWorld {
  2. public static void main(String []args) {
  3. System.out.println("Hello World!");
  4. try{
  5. exceptiona();
  6. }catch(Exception e){
  7. System.out.println(e.getMessage());
  8. //System.exit(0);//加上这句,finally中的内容就不会运行了
  9. }finally{
  10. System.out.println("结束了");
  11. }
  12. }
  13. static void exceptiona() throws Exception{
  14. throw new Exception("I am you father");
  15. }
  16. }

发表评论

表情:
评论列表 (有 0 条评论,425人围观)

还没有评论,来说两句吧...

相关阅读