Exam 12: Exception Handling

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

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:
Verified

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:
Verified

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:
Verified

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)

Some programmers refer to a catch block as a catch ____.

(Multiple Choice)
4.8/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.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)

What advantages does object-oriented exception handling provide?

(Essay)
4.8/5
(48)

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

(True/False)
4.9/5
(47)

What are unchecked exceptions? Give an example.

(Essay)
4.7/5
(43)

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)

What are the elements that make up a try block?

(Essay)
4.8/5
(45)

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

(Multiple Choice)
4.8/5
(37)

   The figure above shows a call stack. Explain how a call stack works. The figure above shows a call stack. Explain how a call stack works.

(Essay)
4.9/5
(32)

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)

The parent class of Error is ____.

(Multiple Choice)
4.8/5
(50)
Showing 1 - 20 of 66
close modal

Filters

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