private void addButton_Click(object sender, EventArgs e) { try { if (titleBox.Text.Trim(' ').Equals("")) { throw new Exception("Dėstomo dalyko pavadinimas negali būti tusčias"); } List <Subject> subjectsList = otherData.GetAllSubjects(); foreach (Subject subject in subjectsList) { if (subject.Title == titleBox.Text) { throw new Exception("Jau egzistuoja toks dėstomas dalykas"); } } otherData.AddNewSubject(titleBox.Text, descriptionBox.Text); MessageBox.Show("Sėkmingai pridėjote naują dėstomą dalyką"); titleBox.Clear(); descriptionBox.Clear(); } catch (Exception exc) { MessageBox.Show(exc.Message); } }