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 6582433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:16:46+00:00 2026-05-25T16:16:46+00:00

We have received Java code from a software supplier. It contains a lot of

  • 0

We have received Java code from a software supplier. It contains a lot of try-catch blocks with nothing in the catch part. They’re all over the place. Example:

        try {
            spaceBlock.enable(LindsayModel);
        } catch (Exception e) {
        }

My questions are: Is the above acceptable practice? If so, when? Or should I just go ahead and remove all of these “bogus” try and catch statements?

To me this looks like terrible practice, but I’m not experienced enough in Java to tell for sure. Why catch errors if you’re not going to do anything with them? Seems to me, you would only do that if you were confident that an exception would be of absolutely no consequence and you don’t care if one occurs. However, this is not really the case in our particular application.

EDIT To give some context: We bought a Java-scriptable product from the supplier. Alongside the product, they provided a large proof-of-concept script tailored to our needs. This script came “free of charge” (though we wouldn’t have bought the product if it hadn’t come with the script) and it “works”. But the script is a real pain to build upon, due to many things that even I as a Java novice recognise as awful practice, one instance being this bogus try-catch business.

  • 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-25T16:16:47+00:00Added an answer on May 25, 2026 at 4:16 pm

    This is indeed terrible practice. Especially the catching of Exception rather than something specific gives off a horrible smell – even a NullPointerException will be swallowed. Even if it is assured that a particular thrown exception is of no real consequence, one should always log it at the very least:

    try {
        // code
    }
    catch (MyInconsequentialException mie) {
       // tune level for this logger in logging config file if this is too spammy
       MY_LOGGER.warning("Caught an inconsequential exception.", mie);
    }
    

    However it is unlikely an exception is completely meaningless in this situation. I recommend researching exactly what exception(s) the application’s code is intending to swallow here, and what they would really mean for the execution.

    One important distinction is whether the try/catches are used to swallow checked exceptions. If this is the case, it probably indicates extreme apathy on the programmer’s part – somebody just wanted his/her code to compile. At the least, the code should be amended:

    try {
       // code
    }
    catch (SpecificCheckedException sce) {
       // make sure there is exception logging done farther up
       throw new RuntimeException(sce);
    }
    

    This will rethrow the exception wrapped in an unchecked RuntimeException, effectively allowing the code to compile. Even this can be considered a bandaid however – best practice for checked exceptions is to handle them on an individual basis, either in the current method or farther up by adding throws SpecificCheckedException to the method signature.

    As @Tom Hawtin mentioned, new Error(sce) can be used instead of new RuntimeException(sce) in order to circumvent any additional Exception catches farther up, which makes sense for something that isn’t expected to be thrown.

    If the try/catch is not being used to swallow checked exceptions, it is equally dangerous and should simply be removed.

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

Sidebar

Related Questions

I have received some code from another team and started to simple improvement and
I have received an assembly from a third party. I need to add it
We have received some JavaScript from an agency that looks wrong, but works. For
I have added some code which compiles cleanly and have just received this Windows
I have a web application that processes events and audio received from a specialised
i have a java code in that i must send a attachment , it
I have a webservice in java that receives a list of information to be
I have received a content export of a MOSS 2007 site which I need
I have received requirements that ask to normalize text box content when the user
I'm sure we all have received the wonderfully vague Object reference not set to

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.