Answers to Self-Test Questions

  1. 1

    Try block entered.
    Exception: Time Limit Exceeded.
    After catch block.
  2. 2

    Try block entered.
    Leaving try block.
    After catch block.
  3. 3 An exception is an object. For example, in the following code, Exception is a constructor for the class Exception:

    throw new Exception("Time Limit Exceeded.");

    The expression

    new Exception("Time Limit Exceeded.");

    creates an exception object.

  4. 4 Yes, it is perfectly valid, although it is unlikely that you would ever have a good reason to use it.

  5. 5 The behavior would not change. The new code is equivalent to the old code it replaces.

  6. 6

    throw new Exception("Time Limit Exceeded.");

    Note that the following is an if statement, not a throw statement, even though it contains a throw statement: ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.