JavaSE 基础 第47节 获取异常信息

2016-06-30

1 获取异常信息
程序发生异常的时候,程序就直接从try执行到catch语句块,不再继续往下执行。

package com.java1995;
//结束方法
//return;
//结束程序
//System.exit(0);
public class TryCatchTest {
    
    public static void main(String[] args) {
                    int count=9;
                
                try{
                    
//                    int temp=count/0;
//                    int[] arr=new int[]{1,2,3,4,5};
                    
//                    int temp=arr[90];
                    
                    String a="aaa";
                    Integer.parseInt(a);
                    
                    System.out.println("检测程序...");
                    
                }catch(ArithmeticException e){
                    System.out.println("发生了ArithmeticException异常");
                }catch(ArrayIndexOutOfBoundsException e){
                    System.out.println("发生了ArrayIndexOutOfBoundsException异常");
                }catch(Exception e){
                    System.out.println("所有的异常都会被我捕获");
                }
                finally{
                    System.out.println("finally");
                }
                System.out.println("程序运行结束");
    }
    
}

 

【参考资料】

[1] Java轻松入门经典教程【完整版】

 

posted @ 2016-06-30 18:43  岑亮  阅读(217)  评论(0编辑  收藏  举报