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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:09:19+00:00 2026-05-11T02:09:19+00:00

I have this factory method in java: public static Properties getConfigFactory() throws ClassNotFoundException, IOException

  • 0

I have this factory method in java:

public static Properties getConfigFactory() throws ClassNotFoundException, IOException {     if (config == null) {         InputStream in = Class.forName(PACKAGE_NAME).getResourceAsStream(CONFIG_PROP);         config = new Properties();         config.load(in);     }     return config; } 

And I want to transform the two checked exceptions into unchecked exceptions. What is the best way to go about this?

Should I just catch the exception and throw a new RuntimeException using the caught exception as the inner exception?

Is there a better way to do this or should I even be attempting to do this in the first place?

EDIT:
Just to clarify. These exceptions will be fatal, as the configuration file is essentially to the operation of the program and all exception will be caught and logged at the top level of my program.

My purpose is to avoid an unnecessary throws exception, exception added to the signature of every method that calls my factory.

  • 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-11T02:09:20+00:00Added an answer on May 11, 2026 at 2:09 am

    A RuntimeException should be used only when the client cannot recover from whatever the problem is. It is occasionally appropriate to do what you are talking about, but more often it is not appropriate.

    If you are using a JDK >= 1.4, then you can do something like:

     try {   // Code that might throw an exception } catch (IOException e) {   throw new RuntimeException(e); } catch (ClassNotFoundException e) {   throw new RuntimeException(e); } 

    and the rethrown RuntimeException will have the original cause included inside it. This way, someone at the top of the thread catching the RuntimeException — your threads do catch RuntimeException so they don’t just silently die, right? — can at least print out the FULL stack trace of the cause.

    But as others have said and will say, exceptions are checked for a reason. Only do this when you are positive that your clients cannot recover from the problem that you are rethrowing as an unchecked exception.

    NOTE: Better than just RuntimeException would be to use a more specific unchecked exception if one is available. For example, if the only reason your method could throw a ClassNotFoundException is because a configuration file is missing, you could rethrow a MissingResourceException, which is an unchecked exception but gives more information about why you are throwing it. Other good RuntimeExceptions to use if they describe the problem you are rethrowing are IllegalStateException, TypeNotPresentException and UnsupportedOperationException.

    Also note that it is ALWAYS a good idea for your threads to catch RuntimeException and at a minimum log it. At least this way you understand why your threads are going away.

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 54k
  • Answers 54k
  • 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
  • added an answer Try to download Eclipse from its site. In my experence… May 11, 2026 at 7:23 am
  • added an answer You should perform the sorting on the client, not in… May 11, 2026 at 7:23 am
  • added an answer I haven't played with msbuild for a while, so I… May 11, 2026 at 7:23 am

Top Members

Trending Tags

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

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.