码迷,mamicode.com
首页 > 编程语言 > 详细

Java异常【不是很常用自己去设计异常,面试和笔试也基本少问到】

时间:2016-08-06 13:06:17      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

这是Arrays工具类的方法:

  private static void rangeCheck(int length, int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            throw new IllegalArgumentException(
                "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
        }
        if (fromIndex < 0) {
            throw new ArrayIndexOutOfBoundsException(fromIndex);
        }
        if (toIndex > length) {
            throw new ArrayIndexOutOfBoundsException(toIndex);
        }
    }

让外部进行调用,也就是public static void sort(char[] a, int fromIndex, int toIndex)这个方法进行调用,范围检查的调用方式,和数据校验有点像

Java异常【不是很常用自己去设计异常,面试和笔试也基本少问到】

标签:

原文地址:http://www.cnblogs.com/chenxuezhouLearnProgram/p/5743761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!