Exam 12: Exception Handling

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

import java.util.*; import java.util.Scanner; public class AssertionExample { public static void main( String args[] ) { Scanner scanner = new Scanner( System.in ); System.out.print( "Enter a number between 0 and 20: " ); int value = scanner.nextInt(); ____ "Invalid number: " + value; System.out.printf( "You have entered %d\n", value ); } } In the code above, when the user enters the number, the scanner.nextInt() method reads the number from the command line. In the blank line provided, create an assert statement that determines whether the entered number is within the valid range (between 0 and 20). If the user entered a number that is out of range, then the "Invalid number" error should occur.

(Essay)
4.9/5
(39)

The code within a finally block cannot execute if the preceding try block identifies an exception.

(True/False)
4.8/5
(32)

What is an Exception class? Give an example.

(Essay)
4.9/5
(41)

import java.util.Scanner; public class AssertTest { public static void main( String args[] ) { Scanner input = new Scanner( System.in ); System.out.print( "Enter a number between 0 and 10: " ); int number = input.nextInt(); assert ( number >= 0 && number <= 10 ) : "Invalid number: " + number; System.out.printf( "You entered %d\n", number ); } } The above code demonstrates the functionality of the assert statement. Explain what happens when an entered number is valid and when an entered number is out of range.

(Essay)
4.9/5
(35)

What are the elements that make up a try block?

(Essay)
4.7/5
(29)

What are unchecked exceptions? Give an example.

(Essay)
5.0/5
(29)

Match each term with the correct statement below. -Should always be true if the program is working correctly

(Multiple Choice)
4.9/5
(37)

The Java compiler does not require that you catch or specify ____ exceptions.

(Multiple Choice)
4.8/5
(29)

Which of the following is NOT a component of a try block?

(Multiple Choice)
4.7/5
(38)

Programs would be less clear if you had to account for ____ exceptions in every method declaration.

(Multiple Choice)
4.8/5
(35)

Placing data conversion attempts in a try block allows you to handle potential data conversion errors caused by careless user entry.

(True/False)
4.9/5
(32)

When an exception is a checked exception, client programmers are forced to deal with the possibility that an exception will be thrown.

(True/False)
4.8/5
(37)

When a program contains multiple catch blocks, how are they handled?

(Essay)
4.8/5
(39)

When you use a(n) ____ statement, you state a condition that should be true, and Java throws an AssertionError when it is not.

(Multiple Choice)
4.9/5
(41)

When you catch an Exception object, you can call ____________________ to display a list of methods in the call stack so you can determine the location of the statement that caused the exception.

(Short Answer)
4.8/5
(48)

A catch block is a method that can be called directly and takes an argument that is some type of exception.

(True/False)
4.9/5
(36)

The ____________________ class comprises less serious errors that represent unusual conditions that arise while a program is running and from which the program can recover.

(Short Answer)
4.8/5
(41)

A(n) ____ statement is one that sends an Exception object out of a method so it can be handled elsewhere.

(Multiple Choice)
4.7/5
(43)

What advantages does object-oriented exception handling provide?

(Essay)
4.9/5
(37)

Unplanned exceptions that occur during a program's execution are also called execution exceptions.

(True/False)
4.9/5
(44)
Showing 41 - 60 of 65
close modal

Filters

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