Summary
I've been given a task to set up a management software (For a small scale artist, so their hardware can definitely cope), however, I would prefer to make this as efficient as possible before giving it to them. The main functionality is done, and now it is mainly just touching up and optimizing.
Code
DateTime DueDate;
try
{
DateTime.TryParse(dteCommission.SelectedDate.Value.Date.ToShortDateString(),
out DueDate);
}
catch(Exception E)
{
MessageBox.Show("Due Date wasn't set. Defaulting to current date.", "Alert",
MessageBoxButton.OK, MessageBoxImage.Warning);
DueDate = DateTime.Parse(DateTime.Now.ToShortDateString());
}
Note: Exception e
was only used to get it done quickly and the true exception is known. The error given is "Nullable object must have a value." System.InvalidOperationException
Question
Is it best to handle this as I am doing or would If-Else work better? And if so, how would I go about implementing it?