异常测试

 1 public class ThrowsTest
 2 {
 3     public static void main(String[] args)
 4     {
 5         try
 6         {
 7             mothed();
 8         } 
 9         catch (Exception ex)
10         {
11             ex.printStackTrace();
12         }
13     }
14 
15     private static void mothed() throws Exception
16     {
17         try
18         {
19             System.out.println("异常前.........");
20             int num = 1 / 0;
21             System.out.println("异常后.........");
22         }
23         finally
24         {
25             System.out.println("异常后的finally中...............");
26         }
27     }
28 }

run:
异常前.........
java.lang.ArithmeticException: / by zero
异常后的finally中...............
at com.gzy.throwsTest.ThrowsTest.mothed(ThrowsTest.java:34)
at com.gzy.throwsTest.ThrowsTest.main(ThrowsTest.java:21)
成功构建 (总时间: 0 秒)

 

posted on 2015-12-02 13:48  starFarming  阅读(153)  评论(0编辑  收藏  举报