Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
New System.DateTime()
Message
 
To
19/01/2006 00:38:21
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01088229
Message ID:
01088356
Views:
7
The questions was: is it bad writing:
new System.DateTime(2004, month, day);
instead of
System.DateTime dt = new System.DateTime(2004, month, day);
I am not too worried about the cost of exceptions, because if there is an exception raised I will give the engineers a call and tell them that their widget is giving me incorrect data :)

Einar

>My only comment on this method of doing this is that, as I've said before, exceptions are expensive and should really not be used for the purpose of validating stuff. I suppose that if, for the most part, you'll only be getting valid data, then the exception will rarely be caught and you'll probably not get that hit all that much.
>
>You decide. <g>
>
>~~Bonnie
>
>
>
>
>>I am given a byte value for month and a byte value for day. I want to verify that this is a correct date and instead of writing a lot of code to do this I figured I would just pass it to the DateTime constructor with the year equal to 2004 (because it was a leap year). So I do something like this:
>>
>>byte month = 0x01;
>>byte day = 0x01;
>>try
>>{
>>  new System.DateTime(2004, month, day);
>>}
>>catch (Exception ex)
>>{
>>  MessageBox.Show(ex.ToString(), "Month and/or day not valid");
>>}
>>
>>
>>I do not need the DateTime object so I do not assign a variable. Is this bad?
>>
>>Should I instead use the following code?
>>
>>byte month = 0x01;
>>byte day = 0x01;
>>try
>>{
>>  System.DateTime dt = new System.DateTime(2004, month, day);
>>}
>>catch (Exception ex)
>>{
>>  MessageBox.Show(ex.ToString(), "Month and/or day not valid");
>>}
>>
>>
>>Or doesn't it matter (estetics aside<s>)?
>>
>>If someone answers I will explain why I am wondering about such a trivial thing :)
>>
>>Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform