HomeCSharpC# Error CS1017 – Catch clauses cannot follow the general catch clause of a try statement

C# Error CS1017 – Catch clauses cannot follow the general catch clause of a try statement

C# Error

CS1017 – Catch clauses cannot follow the general catch clause of a try statement

Reason for the Error & Solution

Catch clauses cannot follow the general catch clause of a try statement

A catch block that does not take any parameters must be the last in a series of catch blocks. For more information on exceptions, see .

Example

The following sample generates CS1017:

// CS1017.cs  
using System;  
  
namespace x  
{  
    public class b : Exception  
    {  
    }  
  
    public class a  
    {  
        public static void Main()  
        {  
            try  
            {  
            }  
  
            catch   // CS1017, must be last catch  
            {  
            }  
  
            catch(b)  
            {  
                throw;  
            }  
        }  
    }  
}  

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...