Exam 12: Exception Handling

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

____ statements are program statements that can never execute under any circumstances.

(Multiple Choice)
4.8/5
(45)

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
(43)

To use a method to its full potential, you must know the method name, return type, type and number of arguments required, and type and number of exceptions the method throws.

(True/False)
4.8/5
(43)

   Using the above code, fill in the blank lines to create a catch block that will catch any type of Exception object and display the message Invalid operation. Using the above code, fill in the blank lines to create a catch block that will catch any type of Exception object and display the message "Invalid operation".

(Essay)
4.8/5
(33)

What is unreachable code and how might using multiple catch blocks cause this? Provide an example.

(Essay)
4.8/5
(37)

   The figure above represents code that executes in the try block any statements that might throw exceptions, along with a catch and finally block. Explain three different outcomes of the try block that would cause the code in the finally block to execute. The figure above represents code that executes in the try block any statements that might throw exceptions, along with a catch and finally block. Explain three different outcomes of the try block that would cause the code in the finally block to execute.

(Essay)
4.7/5
(38)

public static void main(String args[]) {    int a, b;    try    {       a = 0;       b = 42 / a;       System.out.println("This will not be printed.");    }      catch (ArithmeticException e)    {       System.out.println("Division by zero.");    }    System.out.println("After catch statement."); } The program above includes a try block and a catch clause that processes the ArithmeticException generated by the division-by-zero error. Explain how the try and catch blocks operate, and what the output will be following program execution.

(Essay)
4.8/5
(40)

       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.9/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
(32)

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.8/5
(45)

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

(Essay)
4.9/5
(42)

public class exceptions {     public static void main(String Args[])     {        int[] array = new int[3];        try        {           for(int a=0;a           {              array[a] = a;           }           System.out.println(array);        }        catch(ArrayIndexOutOfBoundsException e)        {           System.out.println("Out of bounds");        }     } } In the above code, the line System.out.println(array); gets skipped when an exception occurs. Write a finally block that will execute, and will execute a System.out.println(array); if there is an exception.

(Short Answer)
4.9/5
(31)

       In the example above, the user might not enter an integer, the conversion to an integer might fail, and an exception might be thrown. Why is this a problem and what are some possible options for fixing these types of errors?        In the example above, the user might not enter an integer, the conversion to an integer might fail, and an exception might be thrown. Why is this a problem and what are some possible options for fixing these types of errors? In the example above, the user might not enter an integer, the conversion to an integer might fail, and an exception might be thrown. Why is this a problem and what are some possible options for fixing these types of errors?

(Essay)
4.8/5
(33)

   In the above code, explain the importance of the shaded statement. What occurs if the statement is commented out of the program? In the above code, explain the importance of the shaded statement. What occurs if the statement is commented out of the program?

(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            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.8/5
(41)

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

(Multiple Choice)
4.9/5
(32)

The memory location known as the ____________________ is where the computer stores the list of method locations to which the system must return.

(Short Answer)
4.8/5
(28)
Match each term with the correct statement below.
The parent class of Exception
syntactic salt
A block of code you attempt to execute while acknowledging that an exception might occur
try block
A language feature designed to make it harder to write bad code
fault-tolerant
Correct Answer:
Verified
Premises:
Responses:
The parent class of Exception
syntactic salt
A block of code you attempt to execute while acknowledging that an exception might occur
try block
A language feature designed to make it harder to write bad code
fault-tolerant
Constructs a new exception with the specified detail message
exception handling
Applications designed so that they continue to operate when some part of the system fails
Throwable
Should always be true if the program is working correctly
Exception(String message)
Constructs a new exception with the specified cause and a detail message of cause.toString()
assert statement
A process that is crucial to an organization
Exception(Throwable cause)
Object-oriented techniques to manage errors
mission critical
(Matching)
4.8/5
(38)

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
(41)

What is a finally block and how would a programmer use it?

(Essay)
4.7/5
(40)
Showing 21 - 40 of 66
close modal

Filters

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