private void ButtonAddAd_Click(object sender, EventArgs e) { try { if (textBoxAdContent.TextLength == 0 || textBoxAdName.TextLength == 0) { MessageBox.Show(@"Ad name and content must not be empty!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { _controller.AddAd(this); Close(); } } catch (Exception ex) when(ex is InvalidValueException || ex is AdWithNameAlreadyExistsException) { MessageBox.Show(ex.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }