Re: Checking for a valid date
- From: Jason Pettys <pettys@xxxxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 12:11:38 -0500
I'm not sure whether IsDate uses Exceptions as the primary mechanism. Does anyone know for sure whether IsDate uses an exception for invalid dates (1) always, (2) sometimes, or (3) never?
If I found out that it did I wouldn't use it; here's an msdn blog that talks about it, the best quote being, "...pretend that the throw statement makes the computer beep 3 times, and sleep for 2 seconds. If you still want to throw under those circumstances, go for it."
http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx
The feedback from Jeremy Wilson on this next page seems to indicate that IsDate does not (or at least doesn't use it alone):
http://blogs.crsw.com/mark/archive/2005/04/06/829.aspx
If I found out that IsDate DID rely primarily on an exception for invalid values I would use something similar to that referenced in this next article, the idea being to catch most invalid dates without throwing an exception:
http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci960388_tax293037,00.html
Jason
www.pettysconsulting.com
Kerry Moorman wrote:
Jason,
Doesn't IsDate use this same technique internally?
Kerry Moorman
"Jason Pettys" wrote:
I recommend against this method in most cases; exceptions are resource-intensive and shouldn't really be used for raw user-data validation. It probably wouldn't matter much on a Win Forms app, but I would really back away from this on ASP.NET if you're expecting any volume of traffic.
The IsDate would be a better way to go.
Jason
www.pettysconsulting.com
Armin Zingler wrote:
"romy" <royalizi@xxxxxxxxxxxx> schrieb
What's the easiest way to verify the user had entered a valid date ?
Call Date.Parse in a Try/Catch block. If there's no excecption the date was valid.
Armin
.
- Follow-Ups:
- Re: Checking for a valid date
- From: Kerry Moorman
- Re: Checking for a valid date
- From: Herfried K. Wagner [MVP]
- Re: Checking for a valid date
- From: Armin Zingler
- Re: Checking for a valid date
- References:
- Checking for a valid date
- From: romy
- Re: Checking for a valid date
- From: Armin Zingler
- Re: Checking for a valid date
- From: Jason Pettys
- Re: Checking for a valid date
- From: Kerry Moorman
- Checking for a valid date
- Prev by Date: Re: Why does this code not generate an error?
- Next by Date: Re: Choosing a new laptop
- Previous by thread: Re: Checking for a valid date
- Next by thread: Re: Checking for a valid date
- Index(es):
Relevant Pages
|