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 Exceptions and Exception Handling.
The following sample generates CS0157:
C#
// 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
}
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: