Exam 12: Exception Handling

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

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.9/5
(36)
Match each term with the correct statement below.
Premises:
Object-oriented techniques to manage errors
Responses:
assert statement
fault-tolerant
throws clause.
Correct Answer:
Verified
Premises:
Responses:
Object-oriented techniques to manage errors
assert statement
(Matching)
4.8/5
(42)

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 <= 10 ) : "Invalid number: " + 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)
5.0/5
(33)

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

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

(Essay)
5.0/5
(34)

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

(Multiple Choice)
4.9/5
(35)

In order to use a variable both with a try or catch block and afterward, you must declare the variable before the ____ block begins.

(Multiple Choice)
4.9/5
(44)

The ____ class represents more serious errors from which your program usually cannot recover.

(Multiple Choice)
4.9/5
(34)

If you create an object using Java's  BigDecimal  class, and then perform a division that results in a non-terminating decimal division such as 1/3, but specify that an exact result is needed, a(n) ____ is thrown.

(Multiple Choice)
4.8/5
(43)
Match each term with the correct statement below.
Premises:
A process that is crucial to an organization
Responses:
syntactic salt
fault-tolerant
Exception(String message)
Correct Answer:
Verified
Premises:
Responses:
A process that is crucial to an organization
syntactic salt
(Matching)
4.9/5
(34)

A(n) ____ clause is used in the method header so that applications that use your methods are notified of the potential for an exception.

(Multiple Choice)
4.9/5
(48)

In the case where a method might throw more than one exception type, you specify a list of potential exceptions in the method header by separating them with ____.

(Multiple Choice)
4.9/5
(35)

What things might a programmer do to cause a potential exception in a program?

(Essay)
5.0/5
(42)

The parent class of Error is ____.

(Multiple Choice)
4.8/5
(36)

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

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

(Multiple Choice)
4.8/5
(32)

Which method constructor constructs a new exception with the specified detail message and cause?

(Multiple Choice)
4.8/5
(36)
Match each term with the correct statement below.
Premises:
Should always be true if the program is working correctly
Responses:
syntactic salt
fault-tolerant
stack trace.
Correct Answer:
Verified
Premises:
Responses:
Should always be true if the program is working correctly
syntactic salt
(Matching)
4.8/5
(29)

public class exceptions {     public static void main(String Args[])     {        int[] array = new int[3];        try        {           for(int a=0;a<4;++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.8/5
(39)

When you catch an  Exception  object, you can call ____ to display a list of methods in the call stack so you can determine the location of the statement that caused the exception.

(Multiple Choice)
4.8/5
(46)
Showing 41 - 60 of 79
close modal

Filters

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