This documentation is archived and is not being maintained.

Compiler Error CS0157

Control cannot leave the body of a finally clause

All of the statements in a finally clause must execute.

For more information, see Exception Handling Statements.

The following sample generates CS0157:

// CS0157.cs
using System;
namespace x
{
   public class b : Exception
   {
   }

   public class a
   {
      public static void Main()
      {
         try
         {
         }

         finally
         {
            return;   // CS0157, cannot leave finally clause
         }
      }
   }
}
Show: