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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:11:26+00:00 2026-06-13T22:11:26+00:00

I am supposed to create a sample program for exception handling for file operations

  • 0

I am supposed to create a sample program for exception handling for file operations for my java assignment. I am having trouble understanding since I am a C++ guy. It would be really very helpful if somebody could point out the flaw in my code below. I am referring this article. Eclipse is giving me “Unreachable catch block for FileNotFoundException. This exception is never thrown from the try statement body” error.

import java.io.*;

public class file {

    public static void main(String[] args) {
        String arg1 = args[0];
        String arg2 = args[1];
        System.out.println(arg1);
        System.out.println(arg2);
        File f1, f2;

        try {
            f2 = new File(arg2);
            f1 = new File(arg1);
        }
        catch(FileNotFoundException e) {
        /*
            if(!f1.exists()) {
                System.out.println(arg1 + " does not exist!");
                System.exit(0);
            }
            if(!f2.exists()) {
                System.out.println(arg2 + " does not exist!");
                System.exit(0);
            }


            if(f1.isDirectory()) {
                System.out.println(arg1 + " is a Directory!");
                System.exit(0);
            }
            if(f2.isDirectory()) {
                System.out.println(arg2 + " is a Directory!");
                System.exit(0);
            }

            if(!f1.canRead()) {
                System.out.println(arg1 + " is not readable!");
                System.exit(0);
            }
            if(!f2.canRead()) {
                System.out.println(arg2 + " is not readable!");
                System.exit(0);
            }*/
        }
    }
}
  • 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-13T22:11:27+00:00Added an answer on June 13, 2026 at 10:11 pm

    Look at the docs for the File constructor you’re calling. The only exception it’s declared to throw is NullPointerException. Therefore it can’t throw FileNotFoundException, which is why you’re getting the error. You can’t try to catch a checked exception which the compiler can prove is never thrown within the corresponding try block.

    Creating a File object doesn’t check for its existence. If you were opening the file (e.g. with new FileInputStream(...) then that could throw FileNotFoundException… but not just creating a File object.

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

Sidebar

Related Questions

As a school assignment, I am supposed to create a program in C# that
I am working on an assignment for networking where we are supposed to create
I am making a simple Java program for class that is supposed to output
My program is supposed to create a folder for the uploaded images on the
everytime my page loads, im supposed to create a datatable (also a jquery plugin)
I'm trying to create an installer-like application. Here is what its supposed to do:
I am writing a program for class that is asking us to create a
I am creating a simple reporting program using java and iReport (from jasper), which
I'm trying to create a simple application that is only supposed to be called
I would need to create a php file that will do some work on

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.