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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:11:39+00:00 2026-06-01T07:11:39+00:00

I have learned from various tutorial that If a client can reasonably be expected

  • 0

I have learned from various tutorial that “If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.”

I really want to see the effectiveness of previous statement through some code examples.
e.g.

try {
        br.readLine();
    } catch (IOException e) {

        e.printStackTrace();
    }

Here, IOException is checked Exception.So, how I’m supposed to recover when this Exception occurs? Here, I’m excluding the exception logging,exception re-throwing tasks since they are not actually recovering i.e making things right. So, what modification should be applied here to recover from it?

If there’s a way to recover from it, then the same kind of approach can be applied to the following code :

 try{
    Integer.parseInt("ghg4");
 }catch(NumberFormatException nfe){   
   }

Here NumberFormatException is a Runtime/unchecked exception.So if there’s a way to recover from it, then why is it declared as Runtime exception in the first place?

  • 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-06-01T07:11:41+00:00Added an answer on June 1, 2026 at 7:11 am

    I see three types of exceptions. At the one extreme are the ones you can’t do anything about, like a NullPointerException. You’re going to handle this at a very high level in your code or not at all. It would be ridiculous to check it.

    At the other end are the ones that provide meaningful information. They’re sort of a way of returning a value, sometimes a complex one, when the method already has a return value. They’re also an easy way of jumping up the call stack. (I could write a book about this, but I’ll stop here.) An EOFException ought to be a good example of this. Files have their ends, you’re going to hit it sooner or later, and you don’t want to have to check it every time you do a read. In this case, a checked exception is called for. (I think user1291492 would agree with me on this.) It can happen, and anybody calling a read method should be prepared for it. They’ll much prefer a compiler error to a runtime error.

    Now, with this type of exception, you do not want to put in a stack trace!!! It costs lots of time. The caller just needs to know he hit an EOF, not where in the depths of the IO system it happened! Further, unless there is interesting information to be returned, the exception itself ought to be a final static reference, generated once and used for every EOF that happens.

    The third type, in the middle, are the ones the Java libraries use, like the real EOFException. They make no sense. Either the caller expects never to get an EOF (he put his own marker out there, for instance) and EOFException is of the same nature as a NullPointerException, or he expects it and doesn’t need the hassle and lost processing time of a stack trace. I think the problem is that the Java designers themselves–and I have to admit to having this problem myself when I think about it–which is rarely–weren’t sure which of the first two categories these exceptions might fall into. Even in the same program, in one place the EOFException might indicate the total failure of a program. In another, it might be the normal way to find out that a file has been read. So the end result is a ton of exceptions that do both jobs and do them poorly, forcing the programmer to use try and catch and throws when they can’t do anything anyway and handing them elaborate stack traces they don’t need.

    Addition: I should pehaps note explicitly that you can recover from the real EOFException by simply accepting that you have finished reading the file and carrying on, possibly with a break statement in the catch block. However, there are other, proper ways to catch an EOF, so an EOFException usually means a real problem like a NullPointerException. Oddly, the way I use NumberFormatException, I think it should be checked. Getting “AAA” when I want a number is very common, a user error, not a programming error.

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

Sidebar

Related Questions

I have learned that browsers can only load a few files from the same
I learned from android dev tutorial and now I can make ListView. and it
I have learned so much from http://www.summerofnhibernate.com/ nhibernate screen casts that i wonder why
I have learned that in a class you can declare variables and methods. They
I have learned from somewhere that if I have a unordered collection (eg. a
I have learned from the sencha doc how to create a simple MVC application,
I learned of gist.github.com from Mozilla Ubiquity , and have been using it to
I have learned that Windows uses UTF-16LE on x86/x64 systems. What about Linux? Which
One CSS rule I have learned is that you should use the relative em
I have a stored procedure that inserts batches of millions of rows, emerging from

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.