This time a rather theoretical question. Therefore, I use this function in Eclipse:
CsvReader csv = new CsvReader("src/maindroite.csv");
Which cannot be executed because "Unhandled exception type FileNotFoundException". Well, I understand that I need to add something for the case when the file does not exist, and at this point I usually add a few lines to throw an exception and throw it. But my question is: why do I need to catch the exception , even if the file exists ? And actually, why do I even have this thing Exceptions for some functions, and not for 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 cannot. But I do not need to add an ExceptionHandler for the case when the image does not exist. What is the difference between both functions?
Summarizing:
- Why do I need to add an ExceptionHandler when a do file exists?
- Why should I add an ExceptionHandler for some functions and not others?
Thanks!
source share