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

异常测试

时间:2015-12-02 14:24:54      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:

 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 秒)

 

异常测试

标签:

原文地址:http://www.cnblogs.com/starman/p/5012788.html

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