Compiler Error CS0157
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Error CS0157 

Error Message

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 and Exceptions and Exception Handling (C# Programming Guide).

The following sample generates CS0157:

// CS0157.cs
using System;
namespace MyNamespace
{
   public class MyClass2 : Exception
   {
   }

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

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