diff --git a/.vs/prog2-ss2020-wienkop/v16/.suo b/.vs/prog2-ss2020-wienkop/v16/.suo index f635dc5d3182ca79d8521e4958a69d3467537fca..24e0062c958a73862219b8a5960a5b77ed9334df 100644 Binary files a/.vs/prog2-ss2020-wienkop/v16/.suo and b/.vs/prog2-ss2020-wienkop/v16/.suo differ diff --git a/05Exceptions2/Program.cs b/05Exceptions2/Program.cs index a4fbf41d2e42fd9678e504cfede6e933a410780a..8e3bbfe529695d40fa783913e2aca3eaa4de3aca 100644 --- a/05Exceptions2/Program.cs +++ b/05Exceptions2/Program.cs @@ -8,12 +8,16 @@ namespace _06Exceptions { class Program { - class Quadrierfehler : ArgumentOutOfRangeException + class MyAppExceptions : Exception { - public Quadrierfehler(string Fehlertext) : base(Fehlertext) { } + public MyAppExceptions(string Fehlertext="") : base(Fehlertext) { } } + class MyInputExceptions : MyAppExceptions + { } static int funktion2(int x) { + //MyAppExceptions ex = new MyAppExceptions("Fehlertest"); + //throw ex; if (x < 0) throw new ArgumentOutOfRangeException("Fehler in funktion2"); return x * x * x; @@ -22,7 +26,7 @@ namespace _06Exceptions { funktion2(x); if (x < 0) - throw new Quadrierfehler("So nicht!!!"); + throw new MyAppExceptions("So nicht!!!"); if (x == 0) throw new ArgumentOutOfRangeException("Argument darf nicht null sein"); return x * x; @@ -35,7 +39,7 @@ namespace _06Exceptions funktion(-3); funktion(-2); } - catch (Quadrierfehler q) + catch (MyAppExceptions q) { Console.WriteLine("Quadrierfehler"); } diff --git a/06 UebgDiExceptions/Program.cs b/06 UebgDiExceptions/Program.cs index 2597e370498a095f2d1b7b05877c5315270e2680..9022e20f8923bc28bcd1038e0ccaedae80b84cfe 100644 --- a/06 UebgDiExceptions/Program.cs +++ b/06 UebgDiExceptions/Program.cs @@ -9,26 +9,71 @@ namespace _06_UebgDiExceptions // und Funktion2 ruft Funktion3. Setzen Sie hinter die catches jeweils ein finally // Schreiben Sie entsprechende catch-Methoden, werfen Sie den Fehler weiter // und stellen Sie sicher, dass das Programm unter keinen Umständen mit einer Exception beendet wird! - + class MyAppExceptions : Exception + { + public int fehlerwert; + public MyAppExceptions(string Fehlertext, int fehlerwert) : base(Fehlertext) + { + this.fehlerwert = fehlerwert; + } + } class Program { - static void Funktion2() + static void Funktion1() { + Console.WriteLine("Funktion1"); try { + Funktion2(); + Console.WriteLine("Letzte Anweisung des try-Blocks von Funktion 1"); + } + catch (ArgumentException) + { } + finally + { + Console.WriteLine("Finally von Funktion 1"); + } + Console.WriteLine("Ende von Funktion1"); + } + static void Funktion2() + { + Console.WriteLine("Funktion2"); + try + { + Funktion3(); Console.WriteLine("Letzte Anweisung des try-Blocks von Funktion 2"); } - catch() + catch(MyAppExceptions e) + { + Console.WriteLine($"catch in Funktion 2: {e.Message}, {e.fehlerwert}"); + throw; + } finally { Console.WriteLine("Finally von Funktion 2"); } Console.WriteLine("Ende von Funktion2"); } + static void Funktion3() + { + Console.WriteLine("Funktion3"); + int x = 2; + if (1 < x) + throw new MyAppExceptions("Fehler in Funktion3", 4711); + Console.WriteLine("Ende von Funktion3"); + } + static int errno=0; + static void Funktion3b() + { + int x = 0; + errno = 9999; + int y = 3 / x; + + } static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Funktion1(); } } } diff --git a/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.dll b/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.dll index dfdec278c8ac4837384b5dfe2a065a7d05aac99e..2493fa44bd27762cd19dcfc2cbbc2a6303fc58d4 100644 Binary files a/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.dll and b/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.dll differ diff --git a/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb b/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb index d9107d37c51bede768513d0c534141d97d351369..c110f34e9e21b3d8d0e6c420ca493f46c50cc316 100644 Binary files a/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb and b/06 UebgDiExceptions/bin/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb differ diff --git a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csproj.FileListAbsolute.txt b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csproj.FileListAbsolute.txt index 0ba6c1504e75ef666d7355f1c73029d990e50020..20dcf80347b003799f55e63726deb81e69c0092a 100644 --- a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csproj.FileListAbsolute.txt +++ b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csproj.FileListAbsolute.txt @@ -10,3 +10,4 @@ C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.dll C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.pdb C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.genruntimeconfig.cache +C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06 UebgDiExceptions\obj\Debug\netcoreapp3.1\06 UebgDiExceptions.csprojAssemblyReference.cache diff --git a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csprojAssemblyReference.cache b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csprojAssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..74fe67b1ca671095970d4a7fbcae2417231e8f41 Binary files /dev/null and b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.csprojAssemblyReference.cache differ diff --git a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.dll b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.dll index dfdec278c8ac4837384b5dfe2a065a7d05aac99e..2493fa44bd27762cd19dcfc2cbbc2a6303fc58d4 100644 Binary files a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.dll and b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.dll differ diff --git a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb index d9107d37c51bede768513d0c534141d97d351369..c110f34e9e21b3d8d0e6c420ca493f46c50cc316 100644 Binary files a/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb and b/06 UebgDiExceptions/obj/Debug/netcoreapp3.1/06 UebgDiExceptions.pdb differ