Re: Checking for a valid date

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: Checking for a valid date
    ... Select Break into the debugger when the exception is thrown. ... Now run some code that calls IsDate with an invalid date. ... "Jason Pettys" wrote: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Checking for a valid date
    ... Does anyone know for sure whether IsDate uses an exception for invalid dates always, sometimes, or never? ... If a given format is expected. ...
    (microsoft.public.dotnet.languages.vb)
  • wtf
    ... An unhandled exception occurred during the execution of the ... Exception Details: System.Data.OleDb.OleDbException: Invalid use of Null ... System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) ... Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: AppVerifier stops with Invalid Handle but the call stack looks mas
    ... For invalid handle issues, you can use!htrace debugger extension and look ... ModLoad: 746f0000 7471a000 C:\WINDOWS\System32\Msimtf.dll ... First chance exceptions are reported before any exception handling. ... Stack unwind information not available. ...
    (microsoft.public.win32.programmer.tools)
  • Re: Cant access sending Web Forrms ViewState
    ... The View State is invalid for this page and might be corrupted. ... An unhandled exception occurred during the execution of the ... exception can be identified using the exception stack trace below. ... > Why do I get an empty collection where the sending WebForm has many ...
    (microsoft.public.dotnet.framework.aspnet)