http://community.csdn.net/Expert/topic/4047/4047968.xml?temp=.832226

解决方案 »

  1.   

    public class C
    {
         public C()
        {
        }    .......
        ......    public String A(String B) throws IllegalArgumentException
       {
        if(B.indexOf('|')==-1) throw new IllegalArgumentException("");
       
       }   public static void main(String []args)
       {
            C c1=new C();
            String str1="1,2,3";
            String str2;
            try{
             str2=c1.A(str1);          //这里就提示错误
         }catch(IllegalArgumentException e){
        
         //处理错误
         }
       }
    }
      

  2.   

    H:\javafile\20050419\Test.java:11: illegal start of expression
                   throws new IllegalArgumentException("Wrong");
                   ^
    H:\javafile\20050419\Test.java:31: 'void' type not allowed here
                   System.out.println(e.printStackTrace());
                                                       ^
    2 errors
      

  3.   

    class Test
    {
     private int year;
     private int month;
     private int day;

     public String setDay(int y,int m,int d) throws IllegalArgumentException
         {
              if(d>31)
              {
                   throws new IllegalArgumentException("Wrong");
              }
              year=y;
              month=m;
              day=d;
              String s=String.valueOf(year)+'-'+String.valueOf(month)+'-'+String.valueOf(day);
              return s;
            
         } 

         public static void main(String []args)
         {
            Test t=new Test();
            String s;
              try
              {    
                   s=t.setDay(2001,1,100);
              }
              catch(IllegalArgumentException e)
              {
                   System.out.println(e.printStackTrace());
              }
              System.out.println(s);
         }
    }