Previous | Home | Next |
Exception Handling
Answer: Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not handle, it must specify this behavior so the callers of the method can guard against that exception.
Answer: Exception and Error are the subclasses of the Throwable class. Exception class is used for exceptional conditions that user program should catch. With exception class we can subclass to create our own custom exception.
Error defines exceptions that are not excepted to be caught by you program. Example is Stack Overflow.
Answer: Freeing up other resources that might have been allocated at the beginning of a method.
Answer: Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute.
Answer: No. Try/Catch or Try/finally form a unit.
- Catch (Exception e),
- Catch (Error err),
- Catch (Throwable t)
Answer: It will go for Garbage Collector. And frees the memory.
Answer: We can define multiple exceptions in throws clause.
- Signature is/java/
- type method-name (parameter-list) throws exception-list
(a). True
(b). False
Answer: (a). True
Q.10 The subclass exception should precede the base class exception when used within the catch clause.
(a). True
(b). False
Answer: (a). True
(a). True
(b). False
Answer: (a). True
(a). True
(b). False
Answer: (a). True
(a). True
(b). False
Answer: (a). True
Previous | Home | Next |