zoukankan      html  css  js  c++  java
  • 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("继续!");
            }
    
        }
    
    }

    public class ThrowsDemo {
        
        public static void throwOne() throws IllegalAccessException{
            System.out.println("inside throwOne.");
            throw new IllegalAccessException("ThrowsDemo");
        }
        
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            try
            {
                throwOne();
            }
            catch(IllegalAccessException e)
            {
                System.out.println("Caught" + e);
            }
        }
    
    }

     
  • 相关阅读:
    关键字static
    关键字const有什么含义?
    关于目标
    B/B+树的初步理解(一)
    优先队列(priority_queue)
    哨兵的作用
    数学笑话集(一)

    排序算法小结(一)
    KMP算法
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270844.html
Copyright © 2011-2022 走看看