日期:2014-05-20  浏览次数:20808 次

java新手!为什么数不出来数组越界
import java.io.*;
import java.util.*;
public class TestException1{
  private int x;
  private int y;
  private int z;
  private char a;
  public int testException() throws 

ArrayIndexOutOfBoundsException,IOException
  Scanner read=new Scanner(System.in);
  x=read.nextInt();
  y=read.nextInt();
  char a = (char)new BufferedReader(new InputStreamReader

(System.in)).read();
  try{
   
  if(a=='T'||a=='t')
  { int iArray[]=new int[4]; iArray[10]=3;}
  }catch(ArrayIndexOutOfBoundsException e){throw e;}
  try{
  z=x/y;
  }catch(Exception e){
  System.out.println(e.getMessage());
  } 
  return z;
  }


  public static void main(String[] args){
  try{
  TestOfException test=new TestOfException();
  test.testException();
   
  }catch(ArrayIndexOutOfBoundsException e){
  System.out.println("在main中捕获异常"+e);
  }catch(IOException e){};
  int result=test.testException();
  System.out.println(result);

  }
}


------解决方案--------------------
把异常信息放出来嘛