Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0160

A previous catch clause already catches all exceptions of this or a super type ('type')

A series of catch statements needs to be in decreasing order of derivation. For example, the most derived objects must appear first.

For more information, see Exception Handling Statements.

The following sample generates CS0160:

// CS0160.cs
using System;

public class b : Exception
{
}

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

      catch(Exception)   // Second-most derived; should be second catch
      {
      }

      catch(b)           // CS0160, Most derived; should be first catch
      {
      }

      catch              // Must be last catch
      {
      }
   }
}
Show:
© 2014 Microsoft