java学习——异常处理机制

public class ExceptionDemo2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        int i=0;
        int a[]={1,2,3,4};
        for( i = 0; i<5; i++)
        {
            try
            {
                System.out.print("a[" + i + "]/"+ "=" + (a[i]/i));
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                System.out.print("捕获数组下标越界");
            }
            catch(ArithmeticException e)
            {
                System.out.print("捕获算术异常");
            }
            finally
            {
                System.out.print("finally i=" + i);
            }
            System.out.println("继续!");
        }

    }

}

猜你喜欢

转载自www.cnblogs.com/caiyishuai/p/9947055.html