当我用命令行输入2009 33(33是月)后应该出现异常,但异常后为什么还有部分代码能运行?
import java.util.Calendar;
import java.util.GregorianCalendar;
class GetForm
{
      int year,month;
      GetForm(int yeartemp,int monthtemp)
      {
           year=yeartemp;
           month=monthtemp;
      }
      String getMonth()
      {
            String m[]={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
            return m[month];
      }
      int getDate()
      {
            int d[]={31,28,31,30,31,30,31,31,30,31,30,31};
            return d[month];
      }
      void printForm()
      {
           int monthfirstday;
           int date;
           
           GregorianCalendar objG=new GregorianCalendar(year,month,1);
           try
           {
                 String printmonth=getMonth();
                 
                 System.out.println("\t\t\t"+year+"年"+printmonth);                
           }
           catch(ArrayIndexOutOfBoundsException ae)
           {
                 System.out.println("超出范围");
           }
           monthfirstday=objG.get(Calendar.DAY_OF_WEEK)-1;
           System.out.println("\t日\t一\t二\t三\t四\t五\t六");
           date=getDate();
           if(objG.isLeapYear(objG.get(Calendar.YEAR))&&month==1)
               date++;
           for(int i=0;i<monthfirstday;i++)
           {
                 System.out.print("\t");
           }
           for(int i=1;i<date;i++)
           {
                 if(i<=9)
                    System.out.print(" ");
                 System.out.print("\t"+i);
                 if((monthfirstday+i)%7==0)
                 {
                       System.out.println();
                 }
                 else
                       System.out.print(" ");
           }    
      }
}
public class PrintDate
{
       PrintDate()
       {}
       public static void main(String args[])
       {
             int year=0,month=0;
             if(args.length==2)
             {
                  try
                  {
                        year=Integer.parseInt(args[0]);
                        month=Integer.parseInt(args[1])-1;
                  }
                  catch(ArrayIndexOutOfBoundsException ae)
                  {
                        System.out.println("未给出参数");
                  }
                  catch(NumberFormatException ne)
                  {
                        System.out.println("不是一个数");
                        return;
                  }
             }
             else
             {
                   Calendar objC=Calendar.getInstance();
                   year=objC.get(Calendar.YEAR);
                   month=objC.get(Calendar.MONTH);
             }  
             GetForm obj=new GetForm(year,month);
             obj.printForm();
       }
}

解决方案 »

  1.   

    lz看仔细了 不是之后是之前System.out.println("\t日\t一\t二\t三\t四\t五\t六");
    date = getDate();//throw ArrayIndexOutOfBoundsException
      

  2.   

    但eclipse控制台打印异常堆栈信息和用户打印信息的输出顺序可谓五花八门
      

  3.   

    ?怎么会是在之前呢,当try里面第一次调用getMonth();的时候就应该产生异常吧。因为里面就12个值。当大于他的时候会异常