private static void AddSalarie(Salarie sal) { bool ok = false; try { salaries.AddV2(sal); Console.WriteLine("Le salarié vient d'être créé"); ok = true; if (sal.Matricule == null || sal.Nom == string.Empty || sal.Prenom == null) { throw new ArgumentException("Un des champs n'est pas rempli"); ok = false; } } catch (ArgumentException) { Console.WriteLine("Un des champs n'est pas rempli"); ok = false; } catch (ApplicationException) { Console.WriteLine("Ce salarié existe déjà"); ok = false; } catch (Exception) { Console.WriteLine("Ce salarié existe déjà"); ok = false; } finally { Console.WriteLine(ok); } }
/// <summary> /// Test Exceptions /// </summary> /// <param name="sal"></param> private static void TestException(Salarie sal) { bool ok = false; try { salaries.AddV2(sal); ok = true; } catch (SalarieException ex) { Console.WriteLine(Resource1.Salarie_001); ok = false; } catch (Exception) { Console.WriteLine("Autre Exception"); ok = false; } finally { Console.WriteLine(ok); } }