Esempio n. 1
0
    private static void CatchWithNoException()
    {
        Console.Out.WriteLine("CatchWithNoException called.");

        try
        {
            Console.Out.WriteLine("In try block...");
            var badClass = new BadClass();
            badClass.BadMethod();
            Console.Out.WriteLine("BadMethod called.");
        }
        catch
        {
            Console.Out.WriteLine("Catch entered.");
        }
        finally
        {
            Console.Out.WriteLine("Finally entered.");
        }
    }
Esempio n. 2
0
    private static void CatchException()
    {
        Console.Out.WriteLine("CatchException called.");

        try
        {
            Console.Out.WriteLine("In try block...");
            var badClass = new BadClass();
            badClass.BadMethod();
            Console.Out.WriteLine("BadMethod called.");
        }
        catch (Exception exception)
        {
            Console.Out.WriteLine($"Catch entered - exception type is {exception.GetType().FullName}");
        }
        finally
        {
            Console.Out.WriteLine("Finally entered.");
        }
    }