I have two radio buttons for the user to select the type of movie they like. This is just an example program, as I want to understand throwing exceptions better. When the user clicks the display button it shows the type of movie they selected, between Action or Comedy. If no selection is made it throws an exception, this is the best way I could figure it out, is this going in the right direction?
string selection;
try
{
if (radAction.Checked)
{
selection = radAction.Text;
}
else
if (radComedy.Checked)
{
selection = radComedy.Text;
}
else
throw new ArgumentNullException("Please Choose Movie Type");
MessageBox.Show(selection);
}
catch(ArgumentNullException msg)
{
MessageBox.Show(msg.Message);
}