[英]How can i fix this kind of exception? ArgumentOutOfRangeException
The exception message returns: 异常消息返回:
Year, Month, and Day parameters describe an un-representable DateTime.
年,月和日参数描述了不可表示的DateTime。
The exception hits the monthCalendar1.SelectionStart
异常命中
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);
}
I also tried this one. 我也试过这个。 but another exception has occured
TargetInvocationException
但另一个异常发生了
TargetInvocationException
DateTime check_date = monthCalendar1.SelectionStart;
for (int index = 0; index <= 5; index++)
{
check_date = check_date.AddDays(-index);
}
Exception details: 例外细节:
System.ArgumentOutOfRangeException was unhandled Message=Year, Month, and Day parameters describe an un-representable DateTime.
System.ArgumentOutOfRangeException未处理Message = Year,Month和Day参数描述了无法表示的DateTime。 Source=mscorlib StackTrace: at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day) at System.DateTime..ctor(Int32 year, Int32 month, Int32 day) at TestGetDates.Program.Main(String[] args) in C:\\Documents and Settings\\ngd11\\My Documents\\Visual Studio 2010\\Projects\\TestGetDates\\TestGetDates\\Program.cs:line 15 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
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.