Jump to content

General Error Capture Question


berridgeab

Recommended Posts

Hi

 

Not a problem with Code, just after a more general consensus on wether I should be doing so much error checking.

 

When building scripts, should you (I know the answer is yes in practice), check for every conceivable error that could theoretically occur in your code?

 

An example would be good.

 

Im creating a database (MySQL) which has a transaction Table and a customer table. The user raises a new transaction by clicking a link and any transaction ID created is remembered in the session data.

 

My code does the following to create the transaction ID -

 

1. Clear any old SESSION variables relating to previous Transactions.

2. Attempt to create the transaction ID in MySQL using an INSERT Statement.

3. Check that the INSERT statement was successful, if answer is no, show error.

4. If no Error on 3, then check that I can actually find the transaction in a SELECT statement, if error with statement, or rowcount returns 0, then show error.

5. If no Error on 4, then check that the user hasn't somehow created more than 1 record (hitting the submit button more than once, etc), if rowcount more than 1, then show error.

6. Finally, after checking all of the above, I can confirm that it was successful, get the transaction ID (Its an auto update field) and store it in the session as transactionID. Customer clicks on a link to gather the customer information for the Customer Table.

 

Before I even show them the customer information form, I check -

 

1. Clear any old SESSION variables relating to previous Customers.

2. Check that there is a transaction ID set in the session and that it is numeric, if not then show Error.

3. If there was no error on 2, check that the transaction ID still exists in the database, if not then show error.

4. If there was no error on 3, check that the transaction ID has no customer ID already associated to it, if  it has then show error.

5. Finally after confirming that the transaction exists, and it has no other customer information tied to it, allow customer to fill in the information needed for the Customer Table.

 

Then When they press submit and I go to insert the Customer Data into MySQL I check all of the above again.

 

Am I being too extreme or should I be accounting for every possible error, no matter how remote it could occur?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.