Answers to Self-Test Questions
-
Try block entered. Exception: Time Limit Exceeded. After catch block.
-
Try block entered. Leaving try block. After catch block.
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 Yes, it is perfectly valid, although it is unlikely that you would ever have a good reason to use it.
5 The behavior would not change. The new code is equivalent to the old code it replaces.
-
throw new Exception("Time Limit Exceeded.");
Note that the following is an
if
statement, not athrow
statement, even though it contains athrow
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.