Don't use exceptions for flow control. Use [DateTime.TryParse][1] and [DateTime.TryParseExact][2]. Personally I prefer TryParseExact with a specific format, but I guess there are times when TryParse is better. Example use based on your original code:
DateTime value;
if (!DateTime.TryParse(startDateTextBox.Text, out value))
{
startDateTextox.Text = DateTime.Today.ToShortDateString();
}
Reasons for preferring this approach:
- Clearer code (it says what it wants to do)
- Better performance than catching and swallowing exceptions
- This doesn't catch exceptions inappropriately - e.g. OutOfMemoryException, ThreadInterruptedException. (Your current code could be fixed to avoid this by just catching the relevant exception, but using TryParse would still be better.)
[1]: http://msdn.microsoft.com/en-us/library/system.datetime.tryparse.aspx
[2]: http://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact.aspx