E32 Ex1 - 4
This commit is contained in:
parent
2e998063cb
commit
8b634a0758
@ -8,7 +8,14 @@ namespace Exercises_C_Sharp.E32_Exceptions
|
|||||||
{
|
{
|
||||||
//Rufen Sie die Methode ConvertIt auf, ohne dass das Programm abstürzt.
|
//Rufen Sie die Methode ConvertIt auf, ohne dass das Programm abstürzt.
|
||||||
//Code START
|
//Code START
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ConvertIt();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
//Code ENDE
|
//Code ENDE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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:
|
//Sichern sie die Console.ReadLine()-Methode ab, sodass alle Exceptions abgefangen werden. Geben Sie dann die jeweilige Exception aus:
|
||||||
//Code START
|
//Code START
|
||||||
|
try
|
||||||
|
{
|
||||||
//Code ENDE
|
//Code ENDE
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
//Code START
|
//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
|
//Code ENDE
|
||||||
}
|
}
|
||||||
|
@ -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:
|
//Rufen Sie die Methode ThrowException so lange auf, bis alle Exceptions geflogen und auf der Konsole ausgegeben wurden:
|
||||||
//Code Start
|
//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
|
//Code ENDE
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,35 @@ namespace Exercises_C_Sharp.E32_Exceptions
|
|||||||
possible();
|
possible();
|
||||||
}
|
}
|
||||||
//Code START
|
//Code START
|
||||||
catch
|
catch(IOException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(OutOfMemoryException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(ArgumentOutOfRangeException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(FormatException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(OverflowException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(DivideByZeroException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(IndexOutOfRangeException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(ArgumentNullException)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user