Question: 1 -
Which of these keywords must be used to monitor for exceptions?
-
finally
-
catch
-
try
-
throw
Answer:
try
Solution:
Try keywords must be used to monitor for exceptions.
Try keywords must be used to monitor for exceptions.
Question: 2 -
Which of these keywords is not a part of exception handling?
-
thrown
-
finally
-
catch
-
try
Answer:
thrown
Solution:
Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
Question: 3 -
Which statement is true?
-
The Error class is a RuntimeException.
-
Any statement that can throw an Error must be enclosed in a try block.
-
Any statement that can throw an Exception must be enclosed in a try block.
-
catch(X x) can catch subclasses of X where X is a subclass of Exception.
Answer:
catch(X x) can catch subclasses of X where X is a subclass of Exception.
Solution:
Option "catch(X x) can catch subclasses of X where X is a subclass of Exception." is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well. Option B is wrong. The error class is a subclass of Throwable and not Runtime Exception. Option C is wrong. You do not catch this class of error. Option D is wrong. An exception can be thrown to the next method higher up the call stack.
Option "catch(X x) can catch subclasses of X where X is a subclass of Exception." is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well. Option B is wrong. The error class is a subclass of Throwable and not Runtime Exception. Option C is wrong. You do not catch this class of error. Option D is wrong. An exception can be thrown to the next method higher up the call stack.
Question: 4 -
Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
-
finally
-
throw
-
try
-
catch
Answer:
catch
Solution:
If an exception occurs within the try block, it is thrown and cached by catch block for processing.
If an exception occurs within the try block, it is thrown and cached by catch block for processing.
Question: 5 -
When does Exceptions in Java arises in code sequence?
-
Compilation Time
-
None of the mentioned
-
Run Time
-
Can Occur Any Time
Answer:
Run Time
Solution:
Exceptions in Java are run-time errors.
Exceptions in Java are run-time errors.