ASP.Net 2.0 Correctly throw exception

S

Steve B.

Hi,

I'm wondering how to correctly throw exception within ASP.Net pages.

I've page wich which waits for an "id" parameter in the querystring. I want
to validate this param.

I've wrote this code :

if (Page.Request.QueryString["id"] == null)

{

throw new ArgumentNullException("id");

}

int id;

object o;

if (!int.TryParse(Request.QueryString["id], out id) || (o =
GetObjectFromDataBase(id)) == null)

{

throw new ArgumentOutOfRangeException("Inexistant or invalid ID", "id");

}

else

{

DoSomethingWithO(o);

}



Is it the correct exceptions to throw when validating query string
arguments?

Thanks in advance,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,380
Latest member
LatonyaEde

Latest Threads

Top