473,493 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validating input parameters

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
Nov 16 '05 #1
5 2433
Throw the exception and catch it outside of the object.

-benny

sourabh wrote:
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


Nov 16 '05 #2
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.

--
Regards,
Kristofer Gafvert - IIS MVP
http://www.ilopia.com - When you need help!
"sourabh" <so************@induslogic.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #3
Thanks
"Kristofer Gafvert" <kg******@NEWSilopia.com> wrote in message
news:ei****************@TK2MSFTNGP10.phx.gbl...
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.

--
Regards,
Kristofer Gafvert - IIS MVP
http://www.ilopia.com - When you need help!
"sourabh" <so************@induslogic.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl...
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


Nov 16 '05 #4

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

Nov 16 '05 #5
When validating parameters of this kind the convention is to use.

either:
ArgumentException
ArgumentNullException
or
ArgumentOutOfRangeException

"sourabh" <so************@induslogic.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2870
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought...
3
13981
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
3
2321
by: Terje | last post by:
Hello I have a function like this function checkquantitiy(quantitiy){ if(quantitiy.value != parseInt(quantitiy.value)) { alert(quantitiy.value+" sorry not integer quantitiy"); } } ...
4
2018
by: bremdevnet | last post by:
I have a ASPX page that loads a custom control. This first custom control is made up of 2 textboxes and a Submit button. The user enters data into the form, presses the Submit button and the ASPX...
9
5822
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. ...
3
2315
by: A TO Consultant | last post by:
Hi All, I am working on a web application that uses both asp classic and asp.net pages. We need to validate user input to avoid attacks like sql injection. Can a component be created that both...
232
13062
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
5
6681
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.