private void btnAdd_Click(object sender, EventArgs e) { try { if (Regex.IsMatch(txtId.Text, @"^\d+$")) { _ctrlPosts.Add(Int32.Parse(txtId.Text), txtName.Text, txtType.Text); } else if (txtName.Text != "" && txtType.Text != "" && !Regex.IsMatch(txtId.Text, @"^\d+$")) { MessageBox.Show("ID nu este numar\n", "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { throw new ValidationException("Campurile nu pot fi nule!"); } } catch (ValidationException msg) { if (Regex.IsMatch(txtId.Text, @"^\d+$")) { MessageBox.Show(msg.Message, "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("ID nu este numar\n" + msg.Message, "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } CleanTextBox(); }