Exam 10: Exceptions

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which of the following methods are part of the Exception class and can be used to give information about a thrown exception?

Free
(Multiple Choice)
4.8/5
(43)
Correct Answer:
Verified

C

A(n) _____________________ is an object that defines an unusual or erroneous situation that is typically recoverable.

Free
(Multiple Choice)
4.8/5
(28)
Correct Answer:
Verified

B

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?

Free
(Short Answer)
4.7/5
(35)
Correct Answer:
Verified

This code will throw a NullPointerException since the String object s is never instantiated, but it is dereferenced when the charAt method is called.

Which of the following exceptions are unchecked?

(Multiple Choice)
4.8/5
(49)

What is the difference between a checked exception and an unchecked exception?

(Essay)
4.7/5
(30)

Every line of a(n) __________________ is executed no matter what exceptions are thrown.

(Multiple Choice)
4.9/5
(33)

The Exception class is a subclass of the Object class.

(True/False)
4.8/5
(32)

An exception will be propagated until it is caught and handled or until it is passed out of the main method.

(True/False)
4.9/5
(40)

What is the difference between an exception and an error?

(Short Answer)
4.8/5
(33)

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.

(True/False)
4.9/5
(37)

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.

(Essay)
4.9/5
(34)

Consider the following code fragment. int [] a = new int[50]; a[50] = 100; Will this code fragment throw an exception? Explain.

(Short Answer)
4.7/5
(35)

Every line in a catch block is guaranteed to be executed in all situations.

(True/False)
4.9/5
(38)

Give two examples of methods in the Exception class that can be used to output information about the Exception.

(Short Answer)
4.9/5
(31)

How does a method throw an exception?

(Short Answer)
4.9/5
(39)

Is an exception an object? Explain.

(Essay)
4.9/5
(40)

Write a code fragment that will throw an ArithmeticException. Your code fragment should not use the throw statement.

(Short Answer)
4.9/5
(39)

A(n) ____________________ is used to identify a block of statements that may cause an exception.

(Multiple Choice)
4.9/5
(35)

Which of the following represents the standard input stream?

(Multiple Choice)
4.9/5
(39)

A throw statement is used to begin exception propagation.

(True/False)
4.9/5
(40)
Showing 1 - 20 of 40
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)