Validating input parameters

  • Thread starter Thread starter sourabh
  • Start date Start date
S

sourabh

Hi
I have a basic qus. I am writing a middle-tier component. I have constructor
which takes 3 inputs, here's how it looks
internal ClassName(Database dbToUse, Int64 pk,DateTime Date)

{

}

Now , i want to know should I validate all the inputs before i start using
them, and if so in case of an invalid error whats the best way to report
error. Here on invalid input if I dont initialize the object and return, it
would return a object without any valid fields / memebrs.

Whats th general practice for these type of implementations. Is it feasible
to throw an exception?



-Sourabh
 
If the parameters were not what you expected them to be, throw an exception.
Yes, you should validate the parameters, unless you really know that they
will always be what you expect them to be.
 
Thanks
Kristofer Gafvert said:
If the parameters were not what you expected them to be, throw an exception.
Yes, you should validate the parameters, unless you really know that they
will always be what you expect them to be.
 
I think that if you are developing with a layered architecture, it's always best to do validation when data is collected. my middle tier typically assumes that data would be valid coming in. however, you definitely should but in debug or trace assertions to test the validity of data, so if a problem occurs, you can quickly pinpoint where the problem is

----- sourabh wrote: ----

H
I have a basic qus. I am writing a middle-tier component. I have constructo
which takes 3 inputs, here's how it look
internal ClassName(Database dbToUse, Int64 pk,DateTime Date





Now , i want to know should I validate all the inputs before i start usin
them, and if so in case of an invalid error whats the best way to repor
error. Here on invalid input if I dont initialize the object and return, i
would return a object without any valid fields / memebrs

Whats th general practice for these type of implementations. Is it feasibl
to throw an exception



-Sourab
 
When validating parameters of this kind the convention is to use.

either:
ArgumentException
ArgumentNullException
or
ArgumentOutOfRangeException
 

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

Back
Top