No exceptions occur in called method and run the finally branch - CSharp Custom Type

CSharp examples for Custom Type:try catch finally

Description

No exceptions occur in called method and run the finally branch

Demo Code

using System;/*from  ww  w  . j a  v a  2s  .  c o  m*/

class UsingExceptions
{
   static void Main()
   {
      // No exceptions occur in called method
      Console.WriteLine("Calling DoesNotThrowException");
      DoesNotThrowException();
   }

   // no exceptions thrown
   static void DoesNotThrowException()
   {
      // try block does not throw any exceptions
      try
      {
         Console.WriteLine("In DoesNotThrowException");
      }
      catch
      {
         Console.WriteLine("This catch never executes");
      }
      finally
      {
         Console.WriteLine("finally executed in DoesNotThrowException");
      }

      Console.WriteLine("End of DoesNotThrowException");
   }
}

Result


Related Tutorials