This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
i was told that 'throw' and 'throws' throw objects of unchecked exceptions. and that they can also throw checked exceptions but the compiler ignores them. my question: why does the compiler ignore them? [ November 20, 2007: Message edited by: rachana rayaguda ]
Originally posted by R van Vliet: ... exceptions become checked if your method signature mentions the exception in it's throws clause.
An exception is checked if it's Exception or a subclass but not RuntimeException or a subclass. If the latter is true then it is an unchecked exception. Declaring it has nothing to do with it; if you declare that a method throws a NullPointerException that does not make the NullPointerException a checked exception.
It is true however that a checked exception must either be caught, or declared to be thrown.
Rob is correct. An exception is checked if it does not inherit from RuntimeException. I always think of checked as meaning "checked by the compiler", because the compiler tells me when I forget to surround checked exceptions with a try-catch block. RuntimeExceptions can occur on literally any line of code, so it would be tedious to require try-catch blocks for them.