[Oracle interview]What are Checked and UnChecked Exception?
A checkedexception is some subclass of Exception (or Exception itself), excludingclass RuntimeException and its subclasses.Making an exception checked forcesclient programmers to deal with the possibility that the exception will bethrown. eg, IOException thrown by java.io.FileInputStream's read()method? Unchecked exceptions areRuntimeException and any of its subclasses. Class Error and its subclassesalso are unchecked. With an unchecked exception, however, the compilerdoesn't force client programmers either to catch theexception or declare itin a throws clause. In fact, client programmers may not even know that theexception could be thrown. eg, StringIndexOutOfBoundsException thrown byString's charAt() method? Checked exceptions must be caught at compile time.Runtime exceptions do not need to be. Errors often cannot be.
页:
[1]