Re: Date validation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Ronnie Edgar <RonnieEdgar@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Use a custom validator for client side validation. with a datetime
> validation script as the validationscript.
>
> and server side
>
> something like
>
> try
> {
> datetime.parse (myVariable);
> }
> catch (exception ex)
> {
> throw;
> }

There's no point in catching the exception if you're just going to
throw it again - just let it bubble up if that's the behaviour you
want. If you *don't* want to throw an exception, then catch it (but
preferrably only specific ones rather than just plain Exception).

If you don't want to throw an exception, then as of .NET 2.0, you can
use DateTime.TryParse, which would be preferrable to just catching the
exception. (The exception will be a slight performance penalty - not
nearly the bugbear that it's commonly made out to be, but using
TryParse avoids it without you having to write any custom validation
code.)

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Worth an RCR? static_type_check, polymorphic_type_check,
    ... is evidence of how Ruby 'types' are dynamic in multiple dimensions. ... Which causes the object to be saved bypassing any validation callbacks. ... Either way works (though catching the exception is ...
    (comp.lang.ruby)
  • Re: default namespace / Xmlvalidatingreader
    ... You dont get an exception in the case of the second file, ... validation warning should be thrown. ... XmlReader readerToUse = validatingReader; ...
    (microsoft.public.dotnet.xml)
  • Re: XmlValidatingReader / Default Namespace
    ... You dont get an exception in the case of the second file, ... validation warning should be thrown. ... XmlReader readerToUse = validatingReader; ...
    (microsoft.public.dotnet.xml)
  • Re: Exceptions as return values
    ... The OP stated he derived his exception ... exception type, such as ArgumentException, rather then ApplicationException ... I like exposing the exception as a property of the validation class; ... derives from the base Exception class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Frame-based exception handling problem on Server 2008
    ... appcompt shims to skip exception handlers validation for binaries ... the safe exception handler table has nothing to do with C++. ... Server, as well as on earlier Server versions, so it shouldn't have ...
    (microsoft.public.win32.programmer.kernel)