Deck 10: Exceptions

Full screen (f)
exit full mode
Question
Which of the following exceptions are unchecked?

A) RuntimeException
B) IllegalAccessException
C) NoSuchMethodException
D) ClassNotFoundException
E) none of the above
Use Space or
up arrow
down arrow
to flip the card.
Question
Every line in a catch block is guaranteed to be executed in all situations.
Question
A(n) ____________________ can be used to find the exact line where an exception was thrown during program execution.

A) interface
B) call-stack trace
C) try block
D) catch block
E) none of the above
Question
Which of the following represents the standard input stream?

A) System.in
B) System.out
C) System.err
D) System.instream
E) System.outstream
Question
A(n) _____________________ is an object that defines an unusual or erroneous situation that is typically recoverable.

A) error
B) exception
C) interface
D) try block
E) catch block
Question
A(n) ________________ is an ordered sequence of bytes.

A) exception
B) error
C) input-output flow
D) stream
E) none of the above
Question
A(n) ____________________ is used to identify a block of statements that may cause an exception.

A) call-stack trace
B) error
C) catch block
D) try block
E) none of the above
Question
Which of the following file streams should be explicitly closed to ensure that written data is properly retained?

A) output
B) input
C) error
D) writable
E) readable
Question
Which of the following exception types must always be caught unless they are contained in methods that throw them in the method header?

A) file stream
B) IO
C) checked
D) unchecked
E) none of the above
Question
The Exception class and the Error class are subclasses of the ___________________ class.

A) Throwable
B) Catchable
C) RuntimeProblem
D) CompilerProblem
E) none of the above
Question
Unchecked exceptions must be caught or propogated, or a program will not compile.
Question
The _________________ statement is used to begin exception propogation.

A) propogate
B) relay
C) throw
D) except
E) send
Question
Every line of a(n) __________________ is executed no matter what exceptions are thrown.

A) try block
B) call stack trace
C) catch block
D) interface
E) finally block
Question
If an exception is not caught, a program will __________________________ .

A) not compile
B) terminate abnormally
C) print a message and continue executing
D) all of the above
E) neither a, b nor c
Question
A finally clause is always required in a try-catch block.
Question
Attempting to divide by zero will result in an Error being thrown, not an Exception.
Question
A(n) _____________________ is an object that defines an erroneous situation from which the program usually cannot recover.

A) error
B) exception
C) interface
D) try block
E) catch block
Question
Which of the following methods are part of the Exception class and can be used to give information about a thrown exception?

A) getInfo
B) printInfo
C) printStackTrace
D) getStackTrace
E) none of the above
Question
The Exception class is a subclass of the Object class.
Question
A(n) ____________________ is used to specify how certain exceptions should be handled.

A) finally block
B) try block
C) catch block
D) error
E) none of the above
Question
What is a catch clause?
Question
The getMessage method of the Exception class prints out the stack trace, which helps the user to track down the source of the exception.
Question
When accessing an element of an array, if the index is outside of the range of the indexes of the array, an exception is thrown.
Question
What are the standard I/O streams?
Question
Is the Exception class a subclass of the Error class? Explain.
Question
A throw statement is used to begin exception propagation.
Question
Write a short snippet of code that converts the first element of the String[] args array to an integer. It should catch an exception and print out a message if the first element cannot be converted to an integer.
Question
Consider the following code fragment.
String s;
for(int i = 0; i < s.length(); i++)
System.out.println(s.charAt(i));
What exception will be thrown by this code and why?
Question
What is exception prorogation, and how does it work in Java?
Question
What is the difference between a checked exception and an unchecked exception?
Question
Give two examples of methods in the Exception class that can be used to output information about the Exception.
Question
Consider the following code fragment.
int [] a = new int[50];
a[50] = 100;
Will this code fragment throw an exception? Explain.
Question
Write a code fragment that will throw an ArithmeticException. Your code fragment should not use the throw statement.
Question
How is a finally clause different from a try block and a catch clause?
Question
What is a try block?
Question
In practice, it is important to catch all exceptions that might be thrown by a program.
Question
How does a method throw an exception?
Question
Is an exception an object? Explain.
Question
What is the difference between an exception and an error?
Question
An exception will be propagated until it is caught and handled or until it is passed out of the main method.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Exceptions
1
Which of the following exceptions are unchecked?

A) RuntimeException
B) IllegalAccessException
C) NoSuchMethodException
D) ClassNotFoundException
E) none of the above
A
Explanation: All subclasses of the RuntimeException class are unchecked.
2
Every line in a catch block is guaranteed to be executed in all situations.
False
Explanation: A catch block may not be executed at all. It is only executed when an exception is thrown. All lines in a finally block are guaranteed to be executed.
3
A(n) ____________________ can be used to find the exact line where an exception was thrown during program execution.

A) interface
B) call-stack trace
C) try block
D) catch block
E) none of the above
B
Explanation: A call-stack indicates the exact line where an exception is thrown.
4
Which of the following represents the standard input stream?

A) System.in
B) System.out
C) System.err
D) System.instream
E) System.outstream
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
A(n) _____________________ is an object that defines an unusual or erroneous situation that is typically recoverable.

A) error
B) exception
C) interface
D) try block
E) catch block
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
A(n) ________________ is an ordered sequence of bytes.

A) exception
B) error
C) input-output flow
D) stream
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
A(n) ____________________ is used to identify a block of statements that may cause an exception.

A) call-stack trace
B) error
C) catch block
D) try block
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following file streams should be explicitly closed to ensure that written data is properly retained?

A) output
B) input
C) error
D) writable
E) readable
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following exception types must always be caught unless they are contained in methods that throw them in the method header?

A) file stream
B) IO
C) checked
D) unchecked
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
The Exception class and the Error class are subclasses of the ___________________ class.

A) Throwable
B) Catchable
C) RuntimeProblem
D) CompilerProblem
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
Unchecked exceptions must be caught or propogated, or a program will not compile.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
The _________________ statement is used to begin exception propogation.

A) propogate
B) relay
C) throw
D) except
E) send
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Every line of a(n) __________________ is executed no matter what exceptions are thrown.

A) try block
B) call stack trace
C) catch block
D) interface
E) finally block
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
If an exception is not caught, a program will __________________________ .

A) not compile
B) terminate abnormally
C) print a message and continue executing
D) all of the above
E) neither a, b nor c
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
A finally clause is always required in a try-catch block.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
Attempting to divide by zero will result in an Error being thrown, not an Exception.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
A(n) _____________________ is an object that defines an erroneous situation from which the program usually cannot recover.

A) error
B) exception
C) interface
D) try block
E) catch block
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following methods are part of the Exception class and can be used to give information about a thrown exception?

A) getInfo
B) printInfo
C) printStackTrace
D) getStackTrace
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
The Exception class is a subclass of the Object class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
A(n) ____________________ is used to specify how certain exceptions should be handled.

A) finally block
B) try block
C) catch block
D) error
E) none of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
What is a catch clause?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The getMessage method of the Exception class prints out the stack trace, which helps the user to track down the source of the exception.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
When accessing an element of an array, if the index is outside of the range of the indexes of the array, an exception is thrown.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
What are the standard I/O streams?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
Is the Exception class a subclass of the Error class? Explain.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
A throw statement is used to begin exception propagation.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
Write a short snippet of code that converts the first element of the String[] args array to an integer. It should catch an exception and print out a message if the first element cannot be converted to an integer.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
Consider the following code fragment.
String s;
for(int i = 0; i < s.length(); i++)
System.out.println(s.charAt(i));
What exception will be thrown by this code and why?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
What is exception prorogation, and how does it work in Java?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
What is the difference between a checked exception and an unchecked exception?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
Give two examples of methods in the Exception class that can be used to output information about the Exception.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Consider the following code fragment.
int [] a = new int[50];
a[50] = 100;
Will this code fragment throw an exception? Explain.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
Write a code fragment that will throw an ArithmeticException. Your code fragment should not use the throw statement.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
How is a finally clause different from a try block and a catch clause?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
What is a try block?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
In practice, it is important to catch all exceptions that might be thrown by a program.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
How does a method throw an exception?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
Is an exception an object? Explain.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
What is the difference between an exception and an error?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
An exception will be propagated until it is caught and handled or until it is passed out of the main method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.