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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:05:03+00:00 2026-05-24T07:05:03+00:00

In one of my Java application’s code, I have a try-catch-finally block in which

  • 0

In one of my Java application’s code, I have a try-catch-finally block in which the try block creates some input and output streams and if something goes wrong I close any earlier opened streams in finally.

finally
{
    if(inputStream != null)
        inputStream.close();
    if(outputStream != null)
        outputStream.close();
}

But the <stream>.close() line in Eclipse shows error that “Unhandled exception IOException” in the code for this line and shows that the solution is to include another try/catch in the finally block which would seem to be bad as a programming practice and I don’t want in finally block.

My question is: is it possible to remove this error in Eclipse and use try/catch only when I need it instead of eclipse telling me to do the try/catch add. (Since I am already trying to avoid exception by replacing try/catch with if/else as possible).

  • 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-24T07:05:04+00:00Added an answer on May 24, 2026 at 7:05 am

    This is not an Eclipse error, it is a Java compiler error. Eclipse is merely reporting the Java compilation error for you. There is no way to “turn it off” as the code does not compile without the try/catch clause. It is a safety feature in Java that forces you to handle commonly thrown Exceptions.

    Methods have Exceptions in their signature. For example, InputStream.close() throws an IOException, forcing you to handle it in a try/catch block.

    public void close() throws IOException {
        ...
    

    Throwing an Exception is a way of telling the program that a significant problem – that must be handled – has occurred.

    My question is: is it possible to remove this error in eclipse and use try/catch when I need it otherwise not instead of eclipse telling me to do try/catch add.

    No, it is not possible.

    (Since I am already trying to avoid exception by replacing try/catch with if/else as possible).

    You should generally never try to replace try/catch blocks with if/else blocks. They are two distinct features with distinct purposes.

    Exceptions are an essential Java feature. Read about it and understand it.

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

Sidebar

Related Questions

I have a Java application which requires certain software (one of them being Perl)
For an existing java application (which I do not have the source code) I
I have one java application which is running in my local machine . I
In what situations should one catch java.lang.Error on an application?
I have built a web application using Java EE platform that sells one of
I have created one application in flex that is accessing the Java webservice using
I have web application written in java using Eclipse. It has just one servlet
I have created one java-swing application. The application runs perfectly runs perfect on my
Hi I have only one JDialog box in my Java application.I want to make
I have a java application where the main-thread starts 2 other threads. If one

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.