Java How To Program (late objects) 10e, Ch 11

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is a "resource leak"?

A "resource leak" occurs when an executing program does not properly release a resource when it's no longer needed.

This is an internal list of all the methods that are currently executing. a. invocation list b. call stack c. call list d. list trace

call stack

All exceptions that do not inherit from the Error class or the RuntimeException class are ____ a. unrecoverable exceptions b. unchecked exceptions c. recoverable exceptions d. checked exceptions

checked exceptions

This is one or more statements that are always executed after the try block has executed and after any catch blocks have executed if an exception was thrown. a. try block b. catch block c. finally block d. protected block

finally block

This method can be used to retrieve the error message from an exception object. a. errorMessage b. errorString c. getError d. getMessage

getMessage

This method may be called from any exception object, and it shows the chain of methods that were called when the exception was thrown. a. printinvocationList b. printCallStack c. printStackTrace d. printCallList

printStackTrace

You use this statement to throw an exception manually. a. try b. generate c. throw d. System.exit(0)

throw

When an exception is generated, it is said to have been ____ a. built b. thrown c. caught d. killed

thrown

This informs the compiler of the exceptions that could get thrown from a method. a. throws clause b. parameter list c. catch clause d. method return type

throws clause

You can think of this code as being "protected" because the application will not halt if it throws an exception. a. try block b. catch block c. finally block d. protected block

try block

These are exceptions that inherit from the Error class or the RuntimeException class. a. unrecoverable exceptions b. unchecked exceptions c. recoverable exceptions d. checked exceptions

unchecked exceptions

Should a conventional application catch Error objects? Explain.

Errors are usually serious problems with the underlying Java system; most programs will not want to catch Errors because they will not be able to recover from them.

True or False: When an exception is thrown by code inside a try block, all of the statements in the try block are always executed.

False When an exception is thrown the method stops execution right after the "throw" statement. Any statements following the "throw" statement are not executed.

True or False: You cannot have more than one catch clause per try statement.

False a try statement can have more than one catch clause for each specific type of exception

True or False: The throws clause causes an exception to be thrown.

False the "throws" clause informs the compiler that the method throws one or more exceptions

True or False: IOException serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.

False the RuntimeException serves as a superclass for exceptions that are related to programming errors, such as an out-of-bounds array subscript.

True or False: When in the same try statement you are handling multiple exceptions and some of the exceptions are related to each other through inheritance, you should handle the more general exception classes before the more specialized exception classes.

False you should handle the more specialized exception classes before the more general exception classes.

What does the statement throw exceptionReference do in a catch block?

It rethrows the exception for processing by an exception handler of an enclosing try statement, after the finally block of the current try statement executes.

What happens when a catch block throws an Exception?

First, control passes to the finally block if there is one. Then the exception will be processed by a catch block (if one exists) associated with an enclosing try block (if one exists).

FileNotFoundException inherits from ____ a. Error b. IOException c. JavaException d. FileException

IOException

Why are exceptions particularly appropriate for dealing with errors produced by methods of classes in the Java API?

It's unlikely that methods of classes in the Java API could perform error processing that would meet the unique needs of all users.

List five common examples of exceptions.

Memory exhaustion, array index out of bounds, arithmetic overflow, division by zero, invalid method parameters.

The numeric wrapper classes' "parse" methods all throw an exception of this type. a. ParseException b. NumberFormatException c. IOException d. BadNumberException

NumberFormatException

If no exceptions are thrown in a try block, where does control proceed to when the try block completes execution?

The catch blocks for that try statement are skipped, and the program resumes execution after the last catch block. If there's a finally block, it's executed first; then the program resumes execution after the finally block.

What is the key reason for using finally blocks?

The finally block is the preferred means for releasing resources to prevent resource leaks.

What happens if several catch blocks match the type of the thrown object?

The first matching catch block after the try block is executed.

Give a key advantage of using catch(Exception exceptionName)

The form catch(Exception exceptionName) catches any type of exception thrown in a try block. An advantage is that no thrown Exception can slip by without being caught. You can handle the exception or rethrow it.

What happens to a local reference in a try block when that block throws an Exception?

The reference goes out of scope. If the referenced object becomes unreachable, the object can be garbage collected.

What happens if no catch handler matches the type of a thrown object?

This causes the search for a match to continue in the next enclosing try statement. If there's a finally block, it will be executed before the exception goes to the next enclosing try statement. If there are no enclosing try statements for which there are matching catch blocks and the exceptions are declared (or unchecked), a stack trace is printed and the current thread terminates early. If the exceptions are checked, but not caught or declared, compilation errors occur.

Why would a programmer specify a superclass type as the type in a catch block?

This enables a program to catch related types of exceptions and process them in a uniform manner. However, it's often useful to process the subclass types individually for more precise exception handling.

All exception classes inherit from this class. a. Error b. RuntimeException c. JavaException d. Throwable

Throwable

True or False: Not including polymorphic references, a try statement may have only one catch clause for each specific type of exception.

True

True or False: When an exception is thrown, the JVM searches the try statement's catch clauses from top to bottom and passes control of the program to the first catch clause with a parameter that is compatible with the exception.

True

True or False: You are not required to catch exceptions that inherit from the RuntimeException class.

True

If your code does not handle an exception when it is thrown, it is dealt with by this. a. default exception handler b. the operating system c. system debugger d. default exception generator

default exception handler

This is a section of code that gracefully responds to exceptions. a. exception generator b. exception manipulator c. exception handler d. exception monitor

exception handler

This is the process of converting an object to a series of bytes that represent the object's data. a. serialization b. deserialization c. dynamic conversion d. casting

serialization


Ensembles d'études connexes

Chapter 53: Introduction to the Respiratory System

View Set

Econ Exam 2 Prep. | Quiz (7-10) Questions

View Set

Chapter 2: Theory, Research, and Evidence-Based Practice

View Set

Unit 1 (Computing Systems), Chapter 1: What is Computer Science?

View Set

DH 1 Test #2 seizures case study

View Set

D330 - Data Systems Administration

View Set

Environmental Science Final Review: Chapter 18

View Set