473,796 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ 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(Datab ase 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 2451
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(Datab ase 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******** ******@TK2MSFTN GP10.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(Datab ase 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******@NEWSi lopia.com> wrote in message
news:ei******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP10.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(Datab ase 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(Datab ase 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:
ArgumentExcepti on
ArgumentNullExc eption
or
ArgumentOutOfRa ngeException

"sourabh" <so************ @induslogic.com > wrote in message
news:eG******** ******@TK2MSFTN GP10.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(Datab ase 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
2894
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 a way of doing this would be to compare the submitted strings with the array keys returned by get_html_translation_table(HTML_ENTITIES), but padding this array out with all the remaining normal keyboard characters. But... am I reinventing the...
3
14022
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 dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that someone can help me out with this. Ive been trying to suss it out all week & it's driving me nuts!...
3
2337
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"); } } //End of function
4
2031
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 page should either load a new custom control during the postback or (if validation fails) reload the first custom control. I've attached some validation controls without a problem but the client-side validation doesn't seem to be working...even in...
9
5846
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. The user will be presented with a list of 5 selections they can make. They will then be prompted for which selection they want to enter (which can only be 1-5, no characters or anything like it). Once they select the number, 1 for Euro, 2 for...
3
2327
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 page types can use? Is that the best approach? Would I simply use pattern matching to validate strings and/or remove any unwanted characters? Thanks in advance.
232
13360
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
5
6707
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 = ConfigurationManager.ConnectionStrings.ConnectionString; protected void Page_Load(object sender, EventArgs e) { try
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4130
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 we have to send another system
3
2931
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.