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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:20:33+00:00 2026-05-27T22:20:33+00:00

A quite theoretical question this time. So I’m using this function in Eclipse: CsvReader

  • 0

A quite theoretical question this time. So I’m using this function in Eclipse:

CsvReader csv = new CsvReader("src/maindroite.csv");

Which can’t run because “Unhandled exception type FileNotFoundException”. Ok, I understand that I have to add something for the case where the file doesn’t exist, at which point I usually add a few lines to catche the exception and throw it away. But my question is: why do I need to catch the exception even when the file do exist? And actually, why do I even have this Exception thing for some functions and not others?

For example, let’s say I’m trying to run:

ImageIcon icon1 = new ImageIcon("src/square.jpg");
ImageIcon icon2 = new ImageIcon("src/circle.jpg");

Where “square.jpg” exists but not “circle.jpg”. The program will create icon1, but not icon2, because it can’t. But I don’t need to add an ExceptionHandler for the case where the image doesn’t exist. What is the difference between both functions?

To sum it up:

  • Why do I have to add an ExceptionHandler when the file do exist?
  • Why do I have to add an ExceptionHandler for some functions and not others?

Thanks!

  • 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-27T22:20:34+00:00Added an answer on May 27, 2026 at 10:20 pm

    Why do I have to add an ExceptionHandler when the file do exist?

    Basically you have to add it regardless, because you cannot write conditional code like that, in short there is no way that for the compiler to know before runtime if the file exists or not, therefore the compiler forces yo to put a try/catch block, since FileNotFoundException is a checked exception.

    Why do I have to add an ExceptionHandler for some functions and not others?

    You only have to add try/catch blocks to anything that throws a checked exception, that is anything that does **NOT* inherit from RuntimeException or Error classes. Subclasses of Error and RuntimeException are not checked exceptions and you may either put the try/catch or not the compiler does not care. Since the constructor for ImageIcon does not throw any kind of exceptions and will simply return null if the image does not exist there is no need to do a try/catch block.*

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

Sidebar

Related Questions

The question is quite theoretical. Let's say you're implementing a normal (or small or
Kind of theoretical question. Quite long so feel free to skip if you are
Quite often see in JavaScript libraries code like this: setTimeout(function() { ... }, 0);
I think that this is a newbie type question but I have quite understood
Quite simple really: var req:URLRequest=new URLRequest(); req.url=http://somesite.com; var header:URLRequestHeader=new URLRequestHeader(my-bespoke-header,1); req.requestHeaders.push(header); req.method=URLRequestMethod.GET; stream.load(req); Yet,
I don't have time to read or digest long intricate discussions on theoretical concepts
Here is a twofold question, with a theoretical part, and a practical one: When
I'd like to parse a CSV using context free grammar. I arleady have an
After reading this question and through the various Phone Book sorting scenarios put forth
This is entirely theoretical at this point, but I've been trying to wrap my

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.