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

  • Home
  • SEARCH
  • 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 918433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:22:27+00:00 2026-05-15T18:22:27+00:00

Is it always a bad programming technique to leave a catch block empty when

  • 0

Is it always a bad programming technique to leave a catch block empty when using a try-catch block?

In cases where I am expecting an exception, for example, I am reading 10 values from a file…and converting each value into a String. There is a possibility that one of the 10 values can be a null, but I don’t want to stop my execution at that point and rather continue (obvious use of try catch)

A lame example of what I am trying:

String _text = textReader.ReadLine(); //Assuming this RETURNS a NULL value
try {  
      String _check = _text.ToString(); 
      //Do something with _check, but it should not be NULL
    }
catch (Exception) 
    { //Do Nothing }

At this point, when I catch an exception:

1. I don’t want to log this. Since I am expecting a buggy value.

2. I don’t want to re-throw the exception up the call-stack.

3. I want to simply continue with my execution

Under these cases, is it acceptable to leave the catch empty? Or is this a complete NO-NO and there is a better way to handle this?

I presume this can be a community wiki since it also deals with programming techniques.

– Ivar

  • 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. Editorial Team
    Editorial Team
    2026-05-15T18:22:27+00:00Added an answer on May 15, 2026 at 6:22 pm

    I assume that you mean

     _text.ToString()
    

    and you’re concerned about the case when _text may be null?

    I don’t like your use of exceptions in this case. Put yourself in the mind of someone needing to maintain this code. They see:

    catch (Exception) {  }
    

    Can they really deduce that all this is doing is catching the Null case? They have to consider what other Exceptions might be thrown. At the very least this raises uncertainty in the maintainer’s mind.

    Why could you not code:

     if ( _text != null ) {
          String _check = _nullValue.ToString();
     }
    

    This says exactly what you mean.

    But taking this further, what does getting a value of NULL mean? You’re reading a file that may have 10 values in it. I’m guessing that maybe blank line gives a null for you?

    What do intend if you get:

     1
     2
     <blank line>
     4
     ...
     10  
    

    So that’s 9 good values and a blank line. What will you do if instead you get 10 good values and a blank line? 11 good values? 11 good values and a blank line?

    My point is that silently ignoring oddities in user input is often a bad idea. It’s quite likely that some of the cases above are actually typos. By warning in some of these cases you may be very helpful to the user. This implies that probably most odditities in input need at least some kind of count, if not an actual immediate error log.

    You might, for example, emit a message at the end

    Your file contained 13 lines, two lines were blank. We processed 10 valid values and ignored one.
    

    At the very leasyt for debugging purposes you might have trace statements in the error paths.

    Summary: completely ignoring Exceptions is rarely the right thing to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • 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 I'm not aware of anything GTK specific, but have a… May 16, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer See the answers to this question: There are several approaches:… May 16, 2026 at 8:12 am
  • Editorial Team
    Editorial Team added an answer After a lot of searching and asking around I solved… May 16, 2026 at 8:12 am

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.