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);
            }
        }
    
    }

     
  • 相关阅读:
    javaScript hook
    封装
    javascript 数字验证
    new 运算符
    指针
    js中的call及apply
    每行显示2条数据的分页
    less语言特性(二) —— 混合
    less语言特性(一) —— 变量
    理解响应式布局设计
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270844.html
Copyright © 2011-2022 走看看