import java.io.*;
public class TryTest
{
  public TryTest()
    {
     try {
         int[] a=new int[2];
         a[4]=4;
         System.out.println("After handing exception return here?");
        }
     catch(IndexOutOfBoundsException e)
          {
            System.out.println("Exception msg:"+e.getMessage());
            System.out.println("Exception string:"+e.toString);
            e.printStackTrance();
           }    
     finally
           {
            System.out.println("-------------------");
            System.out.println("finally");
           }  
      System.out.println("NO expection");
    }          
     public static void main(String args[])
      {
      new TryTest();
      }      
  
}

解决方案 »

  1.   

    import java.io.*; 
    public class TryTest 
    { public TryTest() 
        { 
         try { 
             int[] a=new int[2]; 
             a[4]=4; 
             System.out.println("After handing exception return here?"); 
            } 
         catch (IndexOutOfBoundsException e) 
              { 
                System.out.println("Exception msg:"+e.getMessage()); 
                System.out.println("Exception string:"+e.toString());
                e.printStackTrace(); 
               }     
         finally 
               { 
               System.out.println("-------------------"); 
                System.out.println("finally"); 
               }   
          System.out.println("NO expection"); 
        }            public static void main(String args[]) 
          { 
          new TryTest(); 
          }       
       
    }我这边运行通过了,我发现你 catch后面的括号有问题,以及 e.toString()后面你的括号也没有~~
      

  2.   

    数组越界异常啊
     e.toString()
      

  3.   

    多看下exception信息,然后用google查下原因。一般这样都可以解决问题!