private void DispenseButton_Click( object sender, EventArgs e ) { try { // get user input int selection = Convert.ToInt32( SelectionTextBox.Text ); OutputLabel.Text = SnacksString[ selection ].ToString() + " has been dispensed"; } // end try catch ( FormatException formatExceptionParameter ) { // handle case when user enters invalid input MessageBox.Show( "Please enter an integer value.", "Number Format Exception", MessageBoxButtons.OK, MessageBoxIcon.Error ); SelectionTextBox.Text = ""; SelectionTextBox.Focus(); } // end catch catch ( IndexOutOfRangeException indexExceptionParameter ) { // handle case when user inputs number not in array bounds MessageBox.Show( "Please enter a value between 0-3.", "Array Index Out of Bounds Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); SelectionTextBox.Text = ""; SelectionTextBox.Focus(); } // end catch } // end method DispenseButton_Click