Exam 12: Exception Handling
Exam 1: Creating Java Programs61 Questions
Exam 2: Using Data67 Questions
Exam 3: Using Methods Classes and Objects66 Questions
Exam 4: More Object Concepts66 Questions
Exam 5: Making Decisions66 Questions
Exam 6: Looping66 Questions
Exam 7: Characters Strings and the Stringbuilder68 Questions
Exam 8: Arrays66 Questions
Exam 9: Advanced Array Concepts66 Questions
Exam 10: Introduction to Inheritance66 Questions
Exam 11: Advanced Inheritance Concepts66 Questions
Exam 12: Exception Handling66 Questions
Exam 13: File Input and Output66 Questions
Exam 14: Introduction to Swing Components66 Questions
Exam 15: Advanced Gui Topics66 Questions
Exam 16: Graphics66 Questions
Select questions type
If you want to ensure that a user enters numeric data, you should use ____ techniques that provide the means for your program to recover from the mistake.
Free
(Multiple Choice)
4.8/5
(36)
Correct Answer:
C
____ exceptions are the type that programmers should anticipate and from which programs should be able to recover.
Free
(Multiple Choice)
4.8/5
(32)
Correct Answer:
C
An alternative to hard coding error messages into your Exception classes is creating a catalog of possible messages to use. What are the advantages of doing so?
Free
(Essay)
4.8/5
(33)
Correct Answer:
The advantages of creating a catalog of error messages include the following:
All the messages are stored in one location instead of being scattered throughout the program, making them easier to see and modify.
The list of possible errors serves as a source of documentation, listing potential problems when running the application.
Other applications might want to use the same catalog of messages.
If your application will be used internationally, you can provide messages in multiple languages, and other programmers can use the version that is appropriate for their country.
A(n) ____ statement is one that sends an Exception object to a catch block.
(Multiple Choice)
5.0/5
(39)
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.9/5
(41)
Since variables declared within a try or catch block are local to that block, the variable goes out of scope when the try or catch block ends.
(True/False)
4.8/5
(31)
Unplanned exceptions that occur during a program's execution are also called execution exceptions.
(True/False)
4.9/5
(47)
What advantage to programmers does the technique of cycling through the methods in the stack offer? Why?
(Essay)
4.9/5
(42)
The ____ option must be used when running a program in order to see the results of assert statements.
(Multiple Choice)
4.8/5
(38)
Although a method can throw any number of ____ types, many developers believe that it is poor style for a method to throw and catch more than three or four types.
(Multiple Choice)
4.8/5
(37)
____ represents the degree to which a system is resilient to stress, maintaining correct functioning.
(Multiple Choice)
4.9/5
(33)
The Java compiler does not require that you catch or specify ____ exceptions.
(Multiple Choice)
4.8/5
(37)
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.7/5
(39)
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)
Showing 1 - 20 of 66
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)