why exception in java has been classified into checked and unchecked exception rather than keeping it under simply exception?
There are actually 3 types. Checked Exceptions, Runtime Exceptions and Errors. Errors are similar to Exceptions but they are reserved for VM errors like out of memory conditions.
When you have a method, it's name usually indicates what it does, one of the reason for having checked exceptions is to indicate what the method can't do.
So for someone using this method what is it saying?
readFile: Hi, I'm readFile. If you pass a file name string to me I can read it and return the contents as a string. But if the file's not there, I'm sorry but I can't handle that. I'm just giving up and throwing it back at you. Really sorry, but I just can't deal with this situation.
The reason is that this method might be common and could be used with a web application, web service, desktop app, cell phone, etc. Each might would want to hand this situation differently.
This is a simple example. There are many cases where you might not want to throw an exception. This is one of the great debates. If you google you'll find many articles and threads on this topic.
unchecked exceptions are the ones where the fault lies with programmer, where as checked exceptions are the ones where programmer may not be at fault.... unchecked or Run time exception can occur due to faulty design of your code such as dividing integer by zero.... Immagine what would have happened if it was put under checked exception, you would then have to provide try catch block to every integer you use thus making code difficult to read and write.... As for checked exception, they are the ones on which programmer don't have any control.... File name passed to program may not be present or corrupted....
Checked exceptions were a fairly new experiment in Java. They are consistent with compile time type checking in the rest of the language but few (any?) other languages use them. There is much debate on whether they were a good idea overall or not. See the Exceptions chapter in Thinking In Java for a good explanation of the pros & cons.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com