E32 Ex1 - 4

This commit is contained in:
s.schueler.doz 2025-03-03 12:52:42 +01:00
parent 2e998063cb
commit 8b634a0758
4 changed files with 82 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
{
}