if (txtFirstNumber.TextLength > 0 && txtSecondNumber.TextLength > 0) { int exp = 0; //Check that the second number is an integer try { if (isInt(txtSecondNumber.Text) == true) { exp = Convert.ToInt32(txtSecondNumber.Text); } } //If it is not an integer, give an error catch (FormatException) { MessageBox.Show("Second number must be an integert value."); txtSecondNumber.Focus(); }