If it is absolutely required to use textbox to enter date then go for it, but otherwise I'd suggest for date just use DateTimePicker control and whatever value the user has to input, in a button event handler method or any event handler method where you will use the date u can retrieve it by:
DateTime birthday = dateTimePicker1.Value;
This way you don't have to worry about exceptions or formats the user enters the date.
And for handling exceptions in the textbox, its best to make another method where you pass the input text as a string parameter and make some if-else statements to check them and forcefully throw an exception, for example if this is your button click event handler method:
public void Button1_Click(Object sender, EventArgs e)
{
try
{
string inputText = textBox1.Text;
DateTime date1 = dateTimePicker1.Value;
DateTime date1 = dateTimePicker2.Value;
DateTime date1 = dateTimePicker3.Value;
CheckExceptionsMethod(inputText);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void CheckExceptionsMethod(string inputText)
{
if(inputText.Equals("") || inputText.Text == null)
{
throw(new NullEntryException("Please enter a value in the textbox.", null));
}
else if(inputText.Contains("0123456789"))
{
throw(new NumberEntryException("Please do not enter numbers in the textbox.", null));
}
}
Then the last task is for you to create two custom classes for the exceptions you have thrown, because they do not really exist I made them up for you. You can make any custom exception class by inheriting the ApplicationException class. So create two new classes as following, very short coding so no worries. Just inherit the ApplicationException class and make a constructor because when I am throwing the exception I was initializing an object of these classes.
public class NullEntryException : ApplicationException
{
public NullEntryException(string Message, Exception Inner): base(Message, Inner)
{
}
}
public class NumberEntryException : ApplicationException
{
public NumberEntryException(string Message, Exception Inner): base(Message, Inner)
{
}
}