I've already read everything I could about this and I still don't understand how to use checked and unchecked exceptions. I think I can't still grasp the concept. I've read around StackOverflow that it's better to use unchecked rather than checked exceptions, but Eclipse forces me to use checked exceptions, as in FileNotFoundException
(AFAIK, if Eclipse forces me to insert a try/catch block, it's a checked exception). I'm wondering, is there any way to translate checked into unchecked? What the hell is handling per se? I do not understand what it is to handle an exception.
I have this example here, I would really like to know how to handle (?) this. This one is a checked exception, right?
public void readFile() {
File foo = new File("./foo.bar");
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(foo));
} catch (FileNotFoundException e) {
// What should I do here?
}
getDataFromFile(bufferedReader);
}
I've seen various things people do here. Some print a stack trace, that's what I usually do, and I don't see the problem with it. It gives me the information I need to debug. Some people ignore them, I think that shouldn't be done (I saw the JNode OS booter ignoring an exception). Some people simply add the throws
declaration in the signature. Some throw more exceptions inside that thing! (I think maybe this is what using unchecked instead of checked means?)
Furthermore, if you add the throws
declaration, you will be forced to put a try/catch block further up, and that's inconvenient if you have a very big application. I'm sorry, but I am simply clueless. Completely. I'm trying to learn good and elegant design and this is torturing me.