Can someone assist me with the logic to validate the rowindex is in range and also valid the columnName? How would I do that with the logic below.
The task is to create my own custom exception derived from ApplicationException. However for this thread I am looking for the robust logic to valid index and column name.
public static int GetIntValue(this DataTable datatable, int rowindex, string columnName)
{
try
{
//if index is out bounds throw out of bounds;
// return what is asking for
if (datatable != null)
{
if (rowindex > -1 && rowindex < datatable.Rows.Count - 1)
{
return Convert.ToInt32(datatable.Rows[rowindex][columnName]);
}
else
{
//return custom exception
}
}
else
{
//return custom exception
}
}
catch (Exception ex)
{
throw new Exception("GetIntValue: \n" + ex.Message);
}
}