<p>In an attempt to add some parameter validation and correct usage semantics to our application, we are trying to add correct exception handling to our .NET applications.</p>

<p>My question is this: When throwing exceptions in ADO.NET if a particular query returns no data or the data could not be found, what type of exception should I use?</p>

<p>Psuedocode:
(read, don't scrutinize the semantics of the code, I know it won't compile)</p>

<pre><code>public DataSet GetData(int identifier)
{
    dataAdapter.Command.Text = "Select * from table1 Where ident = " + identifier.toString();
    DataSet ds = dataAdapter.Fill(ds);
    if (ds.table1.Rows.Count == 0)
        throw new Exception("Data not found");

    return ds;
}
</code></pre>

As far as ADO.net is concerned, a query that returns zero rows is not an error. If your application wishes to treat such a query as an error, you should create your own exception class by inheriting from Exception.
```
```
public class myException : Exception
{
   public myException(string s) : base() 
   {
      this.MyReasonMessage = s;
   }
}

public void GetData(int identifier)
{
    dataAdapter.Command.Text = "Select * from table1 Where ident = " + identifier.toString();
    DataSet ds = dataAdapter.Fill(ds);
    if (ds.table1.Rows.Count == 0)
        throw new myException("Data not found");
}
```
```