在注释中已经给你标出来了,都是发放名或类名写错了。
这些都是小错误,仔细看就能发现了。
- class FuShuIndexException extends Exception
- {
- }
- class FuArray
- {
- public int method(int[] arr , int index) throws NullPointerException,FuShuIndexException
- {
- if(arr == null)
- throw new NullPointerException();
- if(index < 0)
- throw new FuShuIndexException(); //这个类名少写一个‘t’;
- return arr[index];
- }
- }
-
-
- class ExceptionDemo
- {
- public static void main(String[] args)
- {
- int[] arr = new int[3];
- FuArray fy = new FuArray();
- try
- {
- int num = fy.method(null,-1);
- System.out.println("num = " + num);
- }
- catch(NullPointerException e)
- {
- System.out.println(e.toString());
- System.out.println("has a problem");
- }
- catch(FuShuIndexException e)
- {
- System.out.println("string:" + e.toString()); //这里又是少写个‘t’,方法名写错;
- System.out.println("Fushuindexexception");
- }
- }
- }
复制代码 |