Exam 12: Exception Handling

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags
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:
Verified
Premises:
Responses:
A language feature designed to make it harder to write bad code
Throwable
(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:
Verified
Premises:
Responses:
Language elements that make programming easier
fault-tolerant
(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. 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)

What advantages does object-oriented exception handling provide?

(Essay)
4.9/5
(45)

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:
Verified
Premises:
Responses:
Constructs a new exception with the specified cause and a detail message of cause.toString()
try block
(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 .     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 . 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:
Verified
Premises:
Responses:
Applications designed so that they continue to operate when some part of the system fails
fault-tolerant
(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 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)

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)

What are unchecked exceptions? Give an example.

(Essay)
4.8/5
(35)

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
close modal

Filters

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