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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:23:47+00:00 2026-05-22T19:23:47+00:00

Joshua Bloch in Effective Java said that Use checked exceptions for recoverable conditions and

  • 0

Joshua Bloch in “Effective Java” said that

Use checked exceptions for
recoverable conditions and runtime
exceptions for programming errors
(Item 58 in 2nd edition)

Let’s see if I understand this correctly.

Here is my understanding of a checked exception:

try{
    String userInput = //read in user input
    Long id = Long.parseLong(userInput);
}catch(NumberFormatException e){
    id = 0; //recover the situation by setting the id to 0
}

1. Is the above considered a checked exception?

2. Is RuntimeException an unchecked exception?

Here is my understanding of an unchecked exception:

try{
    File file = new File("my/file/path");
    FileInputStream fis = new FileInputStream(file);   
}catch(FileNotFoundException e){

//3. What should I do here?
    //Should I "throw new FileNotFoundException("File not found");"?
    //Should I log?
    //Or should I System.exit(0);?
}

4. Now, couldn’t the above code also be a checked exception? I can try to recover the situation like this? Can I? (Note: my 3rd question is inside the catch above)

try{
    String filePath = //read in from user input file path
    File file = new File(filePath);
    FileInputStream fis = new FileInputStream(file);   
}catch(FileNotFoundException e){
    //Kindly prompt the user an error message
    //Somehow ask the user to re-enter the file path.
}

5. Why do people do this?

public void someMethod throws Exception{

}

Why do they let the exception bubble up? Isn’t handling the error sooner better? Why bubble up?

6. Should I bubble up the exact exception or mask it using Exception?

Below are my readings

In Java, when should I create a checked exception, and when should it be a runtime exception?

When to choose checked and unchecked exceptions

  • 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-22T19:23:48+00:00Added an answer on May 22, 2026 at 7:23 pm

    Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. They were eliminated in C# for example, and most languages don’t have them. So you can always throw a subclass of RuntimeException (unchecked exception).

    However, I think checked exceptions are useful – they are used when you want to force the user of your API to think how to handle the exceptional situation (if it is recoverable). It’s just that checked exceptions are overused in the Java platform, which makes people hate them.

    Here’s my extended view on the topic.

    As for the particular questions:

    1. Is the NumberFormatException considered a checked exception?
      No. NumberFormatException is unchecked (= is subclass of RuntimeException). Why? I don’t know. (but there should have been a method isValidInteger(..))

    2. Is RuntimeException an unchecked exception?
      Yes, exactly.

    3. What should I do here?
      It depends on where this code is and what you want to happen. If it is in the UI layer – catch it and show a warning; if it’s in the service layer – don’t catch it at all – let it bubble. Just don’t swallow the exception. If an exception occurs, in most of the cases, you should choose one of these:

    • log it and return
    • rethrow it (declare it to be thrown by the method)
    • construct a new exception by passing the current one in constructor
    1. Now, couldn’t the above code also be a checked exception? I can try to recover the situation like this? Can I?
      It could’ve been. But nothing stops you from catching the unchecked exception as well.

    2. Why do people add class Exception in the throws clause?
      Most often because people are lazy to consider what to catch and what to rethrow. Throwing Exception is a bad practice and should be avoided.

    Alas, there is no single rule to let you determine when to catch, when to rethrow, when to use checked and when to use unchecked exceptions. I agree this causes much confusion and a lot of bad code. The general principle is stated by Bloch (you quoted a part of it). And the general principle is to rethrow an exception to the layer where you can handle it.

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

Sidebar

Related Questions

I was reading Joshua Bloch's Effective Java Programming Language Guide . He explains static
Joshua Bloch's Effective Java, Item 51 is not about depending on the thread scheduler
In his talk about Effective Java at 54:15 Joshua Bloch recommends to use get
Joshua Bloch's Effective Java describes a Builder Pattern that can be used to build
I'm reading through Chapter 3 of Joshua Bloch's Effective Java . In Item 8:
Effective Java (Joshua Bloch) Item 17 says : Design and Document or inheritance or
Joshua Bloch in his Effective Java writes : Use the Javadoc @throws tag to
from p.46 Effective Java Joshua Bloch. Item 9: ALways override hashCode when you override
I'm currently reading Effective Java by Joshua Bloch and Item 17 is 'Design and
I'm referring to the paradigm in Item 34 in Effective Java by Joshua Bloch.

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.