繁体   English   中英

我该如何解决这种异常? ArgumentOutOfRangeException

[英]How can i fix this kind of exception? ArgumentOutOfRangeException

异常消息返回:

年,月和日参数描述了不可表示的DateTime。

异常命中monthCalendar1.SelectionStart

            DateTime check_date = monthCalendar1.SelectionStart;

            for (int index = 0; index <= 5; index++)
            {
                check_date = new DateTime(check_date.Year, check_date.Month, check_date.Day - index);

            }

我也试过这个。 但另一个异常发生了TargetInvocationException

                DateTime check_date = monthCalendar1.SelectionStart;

                for (int index = 0; index <= 5; index++)
                {
                    check_date = check_date.AddDays(-index);

                }

例外细节:

System.ArgumentOutOfRangeException未处理Message = Year,Month和Day参数描述了无法表示的DateTime。 Source = mscorlib StackTrace:在System.DateTime.DateToTicks(Int32年,Int32月,Int32日)at System.DateTime..ctor(Int32 year,Int32 month,Int32 day)at TestGetDates.Program.Main(String [] args)在C:\\ Documents and Settings \\ ngd11 \\ My Documents \\ Visual Studio 2010 \\ Projects \\ TestGetDates \\ TestGetDates \\ Program.cs:System.AppDomain.ExecuteAssembly的System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)第15行(String assemblyFile,Evidence assemblySecurity,String [] args)在System.Threading.ExecutionContext.Run的System.Threading.ThreadHelper.ThreadStart_Context(Object state)中的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()(ExecutionContext executionContext,ContextCallback callback) ,对象状态)在System.Threading.ThreadHelper.ThreadStart()InnerException:

  date_tax.Day - index

这可能会产生一个负数,导致此异常,调试并检查其值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM