Exam 12: Exception Handling
Exam 1: Creating Your First Java Classes76 Questions
Exam 2: Using Data81 Questions
Exam 3: Using Methods, Classes and Objects79 Questions
Exam 4: More Object Concepts84 Questions
Exam 5: Making Decisions80 Questions
Exam 6: Looping77 Questions
Exam 7: Characters, Strings and the Stringbuilder82 Questions
Exam 8: Arrays77 Questions
Exam 9: Advanced Array Concepts80 Questions
Exam 10: Introduction to Inheritance78 Questions
Exam 11: Advanced Inheritance Concepts78 Questions
Exam 12: Exception Handling79 Questions
Exam 13: File Input and Output78 Questions
Exam 14: Introduction to Swing Components79 Questions
Exam 15: Using Javafx and Scene Builder65 Questions
Select questions type
Match each term with the correct statement below.
Premises:
A language feature designed to make it harder to write bad code
Responses:
Throwable
mission critical.
try block
Correct Answer:
Premises:
Responses:
(Matching)
4.9/5
(42)
The ____ class comprises less serious errors that represent unusual conditions that arise while a program is running and from which the program can recover.
(Multiple Choice)
4.9/5
(29)
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
(41)
import java.util.*;
public class DivisionMistakeCaught3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int numerator, denominator, result;
try
{
System.out.print("Enter numerator >> ");
numerator = input.nextInt();
System.out.print("Enter denominator >> ");
denominator = input.nextInt();
result = numerator / denominator;
System.out.println(numerator + " / " + denominator + " = " + result);
}
catch(ArithmeticException mistake)
{
System.out.println(mistake.getMessage());
}
catch(InputMismatchException mistake)
{
System.out.println("Wrong data type");
}
}
}
Using the above code, describe what will happen if a user enters two usable integers. What will happen if a user enters an invalid noninteger value? What will happen if the user enters 0 for the denominator?
(Essay)
4.9/5
(32)
If a method throws an exception that it will not catch but that will be caught by a different method, you must also use the keyword ____ followed by an Exception type in the method header.
(Multiple Choice)
4.9/5
(31)
Match each term with the correct statement below.
Premises:
Language elements that make programming easier
Responses:
fault-tolerant
throws clause.
try block
Correct Answer:
Premises:
Responses:
(Matching)
4.8/5
(37)
The example code above uses the getMessage() method. Explain how the getMessage() method makes error message generation more specific to the error encountered.

(Essay)
4.8/5
(28)
The ____ option must be used when running a program in order to see the results of assert statements.
(Multiple Choice)
4.9/5
(39)
Match each term with the correct statement below.
Premises:
Constructs a new exception with the specified cause and a detail message of cause.toString()
Responses:
try block
exception handling
Exception(Throwable cause)
Correct Answer:
Premises:
Responses:
(Matching)
4.9/5
(33)
A(n) ____ is a Java language feature that can help you detect logic errors that do not cause a program to terminate, but nevertheless produce incorrect results.
(Multiple Choice)
4.7/5
(33)
The figures above show the HighBalanceException and CustomerAccount classes. Explain what is involved in creating your own throwable Exception s. Explain what will happen if the CustomerAccount throws a HighBalanceException .


(Essay)
4.8/5
(27)
Match each term with the correct statement below.
Premises:
Applications designed so that they continue to operate when some part of the system fails
Responses:
fault-tolerant
Exception(Throwable cause)
throws clause.
Correct Answer:
Premises:
Responses:
(Matching)
4.9/5
(35)
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();
---Code here---
"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.
(Short Answer)
4.8/5
(37)
The keyword catch followed by an Exception type in the method header is used when a method throws an exception that it will not catch but that will be caught by a different method.
(True/False)
4.9/5
(40)
A catch block is a method that can be called directly and takes an argument that is some type of exception.
(True/False)
4.8/5
(44)
You can place as many statements as you need within a try block, and you can catch as many exceptions as you want.
(True/False)
4.9/5
(43)
Showing 61 - 79 of 79
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)