码迷,mamicode.com
首页 > 其他好文 > 详细

Execption异常 手动和自动抛除异常

时间:2019-03-24 00:27:42      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:ace   trace   ati   except   []   sys   div   on()   nal   

 1 package cn.zmh.Exception;
 2 /*
 3 *
 4 * try{
 5 *   需要被检测的语句
 6 *   }
 7 *   catch(异常类  变量){
 8 *   异常的处理语句
 9 *   }
10 *   finally{
11 *   一定会被执行的语句
12 *   }
13 *
14 *   */
15 public class ExceptionDemo1 {
16     public static void main(String[] args) {
17         //手动抛除异常
18         try {
19             fun(0);
20         } catch (Exception e) {
21             e.printStackTrace();
22         }finally{
23             System.out.println("最终执行的代码");
24         }
25     }
26     // 自动抛除异常
27     public static void fun(int i) throws Exception {
28         if(i==0)
29         throw new Exception();
30         System.out.println(i);
31     }
32 
33 }

 

Execption异常 手动和自动抛除异常

标签:ace   trace   ati   except   []   sys   div   on()   nal   

原文地址:https://www.cnblogs.com/zhangmenghui/p/10586496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!