第八周动手动脑(2018.11.5-11.11)

动手动脑一:

请阅读并运行AboutException.java示例

 1 import javax.swing.*;
 2 
 3 class AboutException {
 4    public static void main(String[] a) 
 5    {
 6       int i=1, j=0, k;
 7       k=i/j;
 8 
 9 
10     try
11     {
12         
13         k = i/j;    // Causes division-by-zero exception
14         //throw new Exception("Hello.Exception!");
15     }
16     
17     catch ( ArithmeticException e)
18     {
19         System.out.println("被0除.  "+ e.getMessage());
20     }
21     
22     catch (Exception e)
23     {
24         if (e instanceof ArithmeticException)
25             System.out.println("被0除");
26         else
27         {  
28             System.out.println(e.getMessage());
29             
30         }
31     }
32 
33     
34     finally
35      {
36              JOptionPane.showConfirmDialog(null,"OK");
37      }
38         
39   }
40 }
View Code

猜你喜欢

转载自www.cnblogs.com/yeshenfeng/p/9930216.html
今日推荐