diff --git a/Exercises/E32_Exceptions/Exercise_1.cs b/Exercises/E32_Exceptions/Exercise_1.cs index df47c89..22b3f72 100644 --- a/Exercises/E32_Exceptions/Exercise_1.cs +++ b/Exercises/E32_Exceptions/Exercise_1.cs @@ -8,7 +8,14 @@ namespace Exercises_C_Sharp.E32_Exceptions { //Rufen Sie die Methode ConvertIt auf, ohne dass das Programm abstürzt. //Code START + try + { + ConvertIt(); + } + catch + { + } //Code ENDE } diff --git a/Exercises/E32_Exceptions/Exercise_2.cs b/Exercises/E32_Exceptions/Exercise_2.cs index b62047a..5444421 100644 --- a/Exercises/E32_Exceptions/Exercise_2.cs +++ b/Exercises/E32_Exceptions/Exercise_2.cs @@ -8,10 +8,29 @@ namespace Exercises_C_Sharp.E32_Exceptions { //Sichern sie die Console.ReadLine()-Methode ab, sodass alle Exceptions abgefangen werden. Geben Sie dann die jeweilige Exception aus: //Code START - + try + { //Code ENDE Console.ReadLine(); //Code START + } + catch(IOException ex) + { + Console.WriteLine(ex.ToString()); + } + catch(OutOfMemoryException ex) + { + Console.WriteLine(ex.ToString()); + } + catch(ArgumentOutOfRangeException ex) + { + Console.WriteLine(ex.ToString()); + } + //Kann auch nur der einzige Catch sein: + catch(Exception ex) + { + Console.WriteLine(ex.ToString()); + } //Code ENDE } diff --git a/Exercises/E32_Exceptions/Exercise_3.cs b/Exercises/E32_Exceptions/Exercise_3.cs index d20ddd4..efc6176 100644 --- a/Exercises/E32_Exceptions/Exercise_3.cs +++ b/Exercises/E32_Exceptions/Exercise_3.cs @@ -10,6 +10,32 @@ namespace Exercises_C_Sharp.E32_Exceptions { //Rufen Sie die Methode ThrowException so lange auf, bis alle Exceptions geflogen und auf der Konsole ausgegeben wurden: //Code Start + bool[] bools = new bool[5]; + + while(true) + { + try {ThrowException();} + catch(FileNotFoundException){bools[0] = true;} + catch(EntryPointNotFoundException){bools[1] = true;} + catch(FieldAccessException){bools[2] = true;} + catch(HttpRequestException){bools[3] = true;} + catch(Exception){bools[4] = true;} + bool temp = false; + foreach(var element in bools) + if(!element) temp = true; + if(!temp) break; + + //ODER: + int number = 0; + try {ThrowException();} + catch(FileNotFoundException){number |= 1;} + catch(EntryPointNotFoundException){number |= 2;} + catch(FieldAccessException){number |= 4;} + catch(HttpRequestException){number |= 8;} + catch(Exception){number |= 16;} + + if(number == 31) break; + } //Code ENDE } diff --git a/Exercises/E32_Exceptions/Exercise_4.cs b/Exercises/E32_Exceptions/Exercise_4.cs index ca2382e..c9f2dc5 100644 --- a/Exercises/E32_Exceptions/Exercise_4.cs +++ b/Exercises/E32_Exceptions/Exercise_4.cs @@ -12,7 +12,35 @@ namespace Exercises_C_Sharp.E32_Exceptions possible(); } //Code START - catch + catch(IOException) + { + + } + catch(OutOfMemoryException) + { + + } + catch(ArgumentOutOfRangeException) + { + + } + catch(FormatException) + { + + } + catch(OverflowException) + { + + } + catch(DivideByZeroException) + { + + } + catch(IndexOutOfRangeException) + { + + } + catch(ArgumentNullException) { }