Compiler Error CS0160
A previous catch clause already catches all exceptions of this or of a super type ('type')
A series of catch clauses needs to be in decreasing order of derivation. For example, the most derived objects must appear first.
For more information, see Exceptions and Exception Handling.
The following sample generates CS0160:
// CS0160.cs
public class MyClass2 : System.Exception {}
public class MyClass
{
public static void Main()
{
try {}
catch(System.Exception) {} // Second-most derived; should be second catch
catch(MyClass2) {} // CS0160 Most derived; should be first catch
}
}
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: