Quiz: Exception Handling

To View Tricks: Login Required

Number of Questions: 11

Question: 1 -

Which of these keywords must be used to monitor for exceptions?

Options:
  1. finally

  2. catch

  3. try

  4. throw

  5. Answer:

    try

    Solution:

    Try keywords must be used to monitor for exceptions.


Question: 2 -

Which of these keywords is not a part of exception handling?

Options:
  1. thrown

  2. finally

  3. catch

  4. try

  5. Answer:

    thrown

    Solution:

    Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.


Question: 3 -

Which statement is true?

Options:
  1. The Error class is a RuntimeException.

  2. Any statement that can throw an Error must be enclosed in a try block.

  3. Any statement that can throw an Exception must be enclosed in a try block.

  4. catch(X x) can catch subclasses of X where X is a subclass of Exception.

  5. 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.


Question: 4 -

Which of these keywords must be used to handle the exception thrown by try block in some rational manner?

Options:
  1. finally

  2. throw

  3. try

  4. catch

  5. Answer:

    catch

    Solution:

    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?

Options:
  1. Compilation Time

  2. None of the mentioned

  3. Run Time

  4. Can Occur Any Time

  5. Answer:

    Run Time

    Solution:

    Exceptions in Java are run-time errors.