error-checking

How to generate a verification code/number ?

Hi, I'm working on an application where users have to make a call and type a verification number with the keypad of their phone. I would like to be able to detect if the number they type is correct or not. The phone system does not have access to a list of valid numbers, but instead it will validate the number against an algorithm (like...

What is the appropriate amount of error-checking?

public void PublicMethod(FooBar fooBar) { if (fooBar == null) throw new ArgumentNullException("fooBar", "fooBar cannot be null"); // log the call [added: Thanks S.Lott] _logger.Log("PublicMethod called with fooBar class " + fooBar.Classification); int action = DetermineAction(); PrivateMethod(fooBar, action); } private void Pr...

Ruby how much error checking is appropriate?

Hey, I'm implementing a few things in Ruby and I was wondering how much error checking is appropriate (or, more precisely, how much error checking should be done by convention)? For example, I'm implementing a method which swaps two elements in an array. The method is very simple: def swap(a,b) @array[a], @array[b] = @array[b], @arr...

What algorithm to use to calculate a check digit?

What algorithm to use to calculate a check digit for a list of digits? The length of the list is between 8 and 12 digits. see also: How to generate a verification code/number? ...

When/how often to check whether object is null

I was writing some code and while unit testing I got a Null Pointer Exception...Now I'm wondering how often should we be checking that object is not null before doing get operations on it? For example, code was: HashMap paramMap = new HashMap(); getSqlMapClientTemplate().queryForObject("reexamination.isAuthorized", paramMap); return ((...

graycode in .NET

Is there a built in gray code datatype anywhere in the .NET framework? Or conversion utility between gray and binary? I could do it myself, but if the wheel has already been invented... ...

Error checking overkill?

What error checking do you do? What error checking is actually necessary? Do we really need to check if a file has saved successfully? Shouldn't it always work if it's tested and works ok from day one? I find myself error checking for every little thing, and most of the time if feels overkill. Things like checking to see if a file has b...

error checking to ensure that a field isn't blank?

My website has an opt-in member directory. Currently, the error checking function simply looks at the form $_POST to see if (!empty($userRealName)) and then allows the member to appear in the list. It took about 30 minutes for someone to show up as a blank name in the list, and upon examination of the database I've determined it's becau...

When you write your code, do you deal with errors proactively or reactively?

In other words, do you spend time anticipating errors and writing code to get around these potential issues, or do you write the code as you see fit and then work through any errors on an issue by issue basis? I've been thinking a lot about this lately and I'm very much a reactive person. I write my code, give it a whirl, go back correc...

C: Throw error on parameter check or let it hit the fan ?

Hi everyone, I have a simple design(?) question. I'm writing a simple program, that has a couple of functions that look like these. float foo (float* m,size_t n){ float result; //do some calculations, for example a sum return result / n; } I have a couple of questions on this, with no intention of re opening some holy ...

Any reason to use a run-time assert instead of compile-time assert?

While reviewing Visual C++ codebase I found a following strange thing. A run-time assert (which is check the condition and throw an exception if the condition is violated) was used in a case when the condition could be evaluated at compile time: assert( sizeof( SomeType ) == sizeof( SomeOtherType ) ); clearly the compiler will evaluat...

Error checking for if a person enters an incorrect name

How would I check for errors. If a person enters an incorrect name or doesnt spell it correctly I would like for a messagebox.show to display a message stating "Incorrect name or spelling" private void button1_Click(object sender, EventArgs e) { String Andrea; String Brittany; String Eric; if (textBo...

Error checking problem

For the most part this does work the problem is the message box pops up for Andrea and Brittany but it works correctly for Eric. If I try to put the else statement after each if statement it still pops up on Brittany, and Andrea, but then also pops up on Eric then. Can someone tell me what i am doing wrong. private void button1_Clic...