I am creating an extension method in C# to retrieve some value from datagridview. Here if a user gives column name that doesnot exists then i want this function to throw an exception that can be handled at the place where this function will be called. How can i achieve this.
   public static T Value<T>(this DataGridView dgv, int RowNo, string ColName)
    {
            if (!dgv.Columns.Contains(ColName))
                throw new ArgumentException("Column Name " + ColName + " doesnot exists in DataGridView.");
            return (T)Convert.ChangeType(dgv.Rows[RowNo].Cells[ColName].Value, typeof(T));
    }