Hello Aru,
Sorry, I would like to correct my explanation give about the way exceptions arre handled in Java. I did some reserch
word from old posts and got the following information. I am wrtting down those things and hope things will be clearer for you. First just think what could be the possible answer of this question in true and false.
JVM will not throw any exceptions. Only programs will throw exceptions.
Exceptions are always thrown by the JVM, usually in response to something in the program. But the program isn't necessarily the cause. Example - if the program is reading data through a connection across the internet, the read() method is declared with a "throws IOException". If I then reach over to the phone line that connects my computer to the internet, and disconnect it, then the JVM will throw an IOException of some sort. Did the program cause this, or did I? I'd say that I did.
All subclasses of RuntimeException (which is an Exception) and Error are constructed and thrown by JVM at appropriate places, when need comes.
All checked exceptions are checked by the compiler whether they are caught properly. Otherwise compile time error occurs. Therefor all subclasses of Exception (excluding RuntimeException), irrespective of in which package they are (as i was explaining earlier), will give error message at compile time if no method/code is written in try block that throw that exception, and you have provided a catch block for it (that is subclass of Exception excluding RuntimeException).
Both Exception and Error can also be thrown by programs through throw new aSubClassOfThrowable(); statement.
If the program throws a checked exception(all subclasses of class Exception excluding RuntimeException ) they must be enclosed by try..catch/try..finally/try..catch..finally statements ...or they must be declared in the throws clause of the appropriate method(s).
Hope things are much clearer now.
Regards,
Rajpal