Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 90107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:49:17+00:00 2026-05-10T22:49:17+00:00

I read somewhere that one should never use error conditions as normal program flow.

  • 0

I read somewhere that one should never use error conditions as normal program flow. Makes excellent sense to me… But

C# application sitting on top of a MySQL db. I need to parse a string value into two parts, an ID, and a value. (The original data come from a Devonian database), then validate the value against a lookup table. So, a couple of original strings might look like this:

‘6776 Purple People Eater’

‘BIK Yellow Polka-Dot Bikini (currently in use)’

‘DCP Deuce Coup’

So, my little utility parses each string into the ID and the description based on the index of the first space (fortunately, consistent). I then pass the ID to the lookup, get the new value and away we go.

Unfortunately, TPTB also decided that we no longer need no stinkin’ Yellow Polka-Dot Bikinis (currently in use). So, BIK does not return a row. Here’s a code snippet:

    foreach (string product in productTokens) {       tempProduct = product.Trim();       if (tempProduct.Length > 0) {         if (tempProduct.Length < 10) {           product_id = tempProduct;         }         else {           int charPosition = tempProduct.IndexOf(' ');           product_id = tempProduct.Substring(0, charPosition);         }         try {           s_product = productAdapter.GetProductName(product_id).ToString();         }         catch (Exception e) {           if (e.Message.ToString() == 'Object reference not set to an instance of an object.') {             s_product = '';           }           else {             errLog.WriteLine('Invalid product ID ' + e.Message.ToString());             Console.WriteLine('Invalid product ID ' + e.Message.ToString());             throw;           } //else         } //catch         if (s_product.Length > 0) {           sTemp = sTemp + s_product + '; ';         }       } //if product.length > 0     } //foreach product in productTokens 

Really, really ugly! Particularly the part where I test for an invalid IDin the catch block. There simply must be a better way to handle this.

If anyone can help me out, I’d really appreciate it.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:49:18+00:00Added an answer on May 10, 2026 at 10:49 pm

    You shouldn’t be calling ToString() at that point, first you should check if the value returned is null;

    object productName = productAdapter.GetProductName(product_id); if ( productName != null ) {     s_product = productName.ToString(); } else {     s_product = String.Empty; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Merge replication is included with MSSQL and is intended for… May 11, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer If your real code is structured like that then you… May 11, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer This link I think is the answer to my question:… May 11, 2026 at 10:33 pm

Related Questions

I've read a statement somewhere that generating UI automatically from DB layout (or business
I'm writing an application in Python (2.6) that requires me to use a dictionary
i am considering moving my images to a subdomain on my website, and i
Basically I'm converting local dates stored in the database into UTC. But I've read

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.