I have a school project where I need to create a value returning method. When testing the program I found that if no value was entered into the text box it causes an error. I tried including a try catch statement but now the method shows not all code paths return a value. Can I use an If else and try catch statement together? If so how would it look, if not is there an easier solution?
Here is the code:
private decimal TaxCharges()
{
decimal tax = 0.06m;
decimal partsTax;
try
{
partsTax = decimal.Parse(partsTextBox.Text) * tax;
taxPartsTextBox.Text = partsTax.ToString("c");
return partsTax;
}
catch
{ MessageBox.Show("Must enter 0 for parts");
}