Java Programming - Exceptions
- Exceptions - Finding the output
- Exceptions - Pointing out the correct statements
The (1), (4), (5) and (6) are the only four that can be thrown.
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
The Throwable class is the superclass of all errors and exceptions in the Java language.
The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch (checked exceptions)
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.
A is wrong. A try statement can exist without catch, but it must have a finally statement.
B is wrong. A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If that catch block completes normally, then the try statement completes normally.
C is wrong. Exceptions of type Error and RuntimeException do not have to be caught, only checked exceptions (java.lang.Exception) have to be caught. However, speaking of Exceptions, Exceptions do not have to be handled in the same method as the throw statement. They can be passed to another method.
If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:
- An exception arising in the finally block itself.
- The death of the thread.
- The use of System.exit()
- Turning off the power to the CPU.