Lösung: Using
Completion requirements
- using System;
- using System.IO;
- class Test
- {
- public static void Main()
- {
- try
- {
- Division div = new Division();
- }
- catch (Exception e)
- { // alle Exceptions mit beliebiger Verschachtelungstiefe ausgeben
- Exception currentEx = e;
- while (currentEx != null)
- {
- Console.WriteLine(currentEx.Message);
- currentEx = currentEx.InnerException;
- }
- }
- Console.ReadKey();
- }
- }
- class Division
- {
- static int zero = 0;
- public Division()
- {
- try
- {
- int j = 1 / zero;
- }
- catch (DivideByZeroException dbze)
- {
- try
- { // Exception handling schlägt fehl (Doppelpunkt im Namen)!
- using (StreamWriter sw = new StreamWriter("ungültig:txt"))
- {
- sw.Write(dbze);
- }
- /* entspricht exaxt:
- StreamWriter sw = null;
- try
- {
- sw = sw = new StreamWriter("ungültig:txt");
- sw.Write(sw);
- }
- finally
- {
- if (sw != null)
- sw.Dispose();
- }
- */
- }
- catch (Exception e)
- { // Exception erneut werfen mit Parameter innerException
- throw new DivideByZeroException(dbze.Message, e);
- }
- }
- }
- }
Last modified: Wednesday, 30 October 2019, 8:59 AM