Which of the following statement is not true regarding error handling and Logging

64) Consider the following code snippet:

System.out.printf("%-12s%8.2f",description,totalPrice);

Which of the following statements is correct?

a) This code will produce 2 columns, with the description field left justified and the totalPrice field right justified.
b) This code will produce 2 columns, with the description field right justified and the totalPrice field right justified.
c) This code will produce 2 columns, with the description field right justified and the totalPrice field left justified.
d) This code will produce 2 columns, with the description field left justified and the totalPrice field left justified

Upgrade to remove ads

Only ₩37,125/year

  • Flashcards

  • Learn

  • Test

  • Match

  • Flashcards

  • Learn

  • Test

  • Match

Terms in this set (27)

Which of the following statements is false?
a. Exception handling enables programmers to write robust and fault-tolerant programs.
b. Exception handling can catch but not resolve exceptions.
c. Exception handling can resolve exceptions.
d. All of the above are true.

b. Exception handling can catch but not resolve exceptions

When an exception occurs it is said to have been ________.
a. caught.
b. thrown.
c. declared.
d. handled.

b. thrown

Which of the following is not included in an exception's stack trace?
a. A descriptive message for the exception.
b. The method-call stack at the time the exception occurred.
c. The name of the exception.
d. Instructions on handling the exception.

d. Instructions on handling the exception

Which of the following statements regarding the throw point of an exception is false?
a. It specifies the point at which the exception must be handled.
b. It is the initial point at which the exception occurs.
c. It is specified as the top row of the method-call stack at the time the exception occurred.
d. All of the above statements are true.

a. It specifies the point at which the exception must be handled.

To catch an exception, the code that might throw the exception must be enclosed in a ________.
a. throws block.
b. catch block.
c. try block.
d. finally block.

c. Try Block

Exceptions can be thrown by ________.
a. the Java Virtual Machine.
b. code in a try block.
c. calls from a try block to other methods.
d. All of the above.

d. All of the above

In the catch block below, what is e?
catch (ArithmeticException e)
{
System.err.printf(e);
}
a. The type of the exception being caught.
b. The name of catch block's exception parameter.
c. A finally block.
d. An exception handler.

b. The name of catch block's Exception parameter.

An uncaught exception ________.
a. is a possible exception that never actually occurs during the execution of the program.
b. is an exception that occurs for which the matching catch clause is empty.
c. is an exception that occurs for which there are no matching catch clauses.
d. is another term for a thrown exception.

c. Is an exception that occurs for which there are no matching catch clauses

Which of the following statements about try blocks is true?
a. The try block must be followed by at least one catch block.
b. The try block must be followed by a finally block.
c. The try block should contain statements that may process an exception.
d. The try block should contain statements that may throw an exception.

d. The try block should contain statements that may throw an exception.

In Java, after an exception is handled, control resumes ---------. This is known as the------model of exception handling.
a. after the last catch block (or the finally block, if there is one), termination
b. after the last catch block (or the finally block, if there is one), resumption
c. just after the throw point, termination
d. just after the throw point, resumption

a. after the last catch block (or the finally block if there is one), termination.

What is the difference between a try block and a try statement?
a. There is no difference; the terms can be used interchangeably.
b. A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.
c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
d. The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.

c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch an/or finally clauses together form a try statement.

The throws clause of a method:
a. specifies the exceptions a method catches.
b. specifies the exceptions thrown by the calling method.
c. specifies the exceptions a method throws.
d. specifies the exceptions a method throws and catches.

c. specifies the exceptions a method throws.

Which of the following errors is synchronous?
a. Divide by zero.
b. Arithmetic overflow.
c. Unsuccessful memory allocation.
d. All of the above.

d. all of the above

All exception classes inherit, either directly or indirectly, from ________.
a. class Error.
b. class RuntimeException.
c. class Throwable.
d. None of the above.

c. class Throwable

Which of the following exceptions is a checked exception?
a. ArithmeticException.
b. IOException.
c. RuntimeException.
d. InputMismatchException.

b. IOException

If the catch-or-declare requirement for a checked exception is not satisfied ________.
a. the compiler will issue an error message indicating that the exception must be caught.
b. the compiler will issue an error message indicating that the exception must be caught or declared.
c. a stack trace will be displayed indicating the exception that has occurred and where it occurred.
d. a stack trace will be displayed, along with a message indicating that the exception must be caught.

b. the compiler will issue an error message indication that the exception must be caught or declared.

Which of the following statements is false?
a. A finally block is placed after the last catch block.
b. A finally block typically releases resources acquired in the corresponding try block.
c. The finally block and try block can appear in any order.
d. A finally block is optional

c. The finally block and the try block can appear in any order.

Which of the following statements is true?
a. The code in a finally block is executed only if an exception occurs.
b. The code in a finally block is executed only if an exception does not occur.
c. The code in a finally block is executed only if there are no catch blocks.
d. None of the above are true.

d. None of the above are true. The code in the finally block is always executed provided that the flow of control enters the corresponding try block.

After a finally block has finished executing (and there are no exceptions to be handled), ________.
a. control proceeds to the first statement after the finally block.
b. control returns to the throw point.
c. the application exits.
d. control proceeds to the first statement after the last catch block.

a. control proceeds to the first statement after the finally block.

Which of the following statements is true?
a. The throw statement is used to throw an exception.
b. The throw statement is used to specify that a method will throw an exception.
c. The throw statement is used to access an exception parameter.
d. All of the above.

a. the Throw statement is used to Throw an Exception.

When an unchecked exception occurs in a method but is not caught, ________.
a. the method-call stack is "unwound."
b. the method terminates.
c. all local variables in that method go out of scope.
d. All of the above.

d. All of the above

Which of the following statements is false?
a. All exceptions must derive from the class Throwable.
b. The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.
c. The class Throwable provides the method getMessage that returns the descriptive string stored in an exception.
d. The string returned from class Throwable's getMessage method contains the name of the exception's class.

b. the class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.

Chained exceptions are useful for finding out about ________.
a. exceptions thrown using the chained keyword.
b. checked exceptions only.
c. an original exception that was caught before the current exception was thrown.
d. the current exception's chain of superclasses.

c. an original exception that was caught before the current exception was thrown.

Which of the following statements is true?
a. Using existing exceptions makes the program less robust.
b. Always create your own exception classes.
c. Like any other class, an exception class can contain fields and methods.
d. The new exception class should extend RuntimeException if the program should be required to handle the exception.

c. Like any other class, an exception class can contain fields and methods.

Which of the following is true?
a. A precondition must be true when a method is invoked.
b. A postcondition must be true when a method successfully returns to its caller.
c. Both (a) and (b).
d. Neither (a) nor (b).

c. both (a) and (b)

Which of the following are types of assertions?
a. Preconditions.
b. Postconditions.
c. Conditions in control statements.
d. (a) and (b).

d. (a) and (b)

Which of the following statements about the try-with-resources statement is false?
a. The try-with-resources statement simplifies writing code in which you obtain a resource, use it in a try block and release the resource in a corresponding finally block..
b. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then the statement implicitly calls the resource's close method at the end of the try block.
c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block.
d. Each resource must be an object of a class that implements the AutoCloseable interface—such a class has a close method

c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; the you explicitly call the resources close method at the end of the try block.

Students also viewed

Chapter 11: Exception Handling

27 terms

Python Summary Test 2 (Chapter 4-5)

70 terms

CS 1101: Programming Fundamentals

165 terms

CS 1101

163 terms

Sets found in the same folder

Chapter 14: String Builders

33 terms

Chapter 18: Recursion

16 terms

Chapter 15: Files, Streams and Object Serialization

29 terms

Chapter 8 Classes and Objects: A Deeper Look

28 terms

Other sets by this creator

Security+ Ports and Vocab

36 terms

Chapters 7-9

44 terms

Chapter 4-6

28 terms

IAS TEST 2

30 terms

Verified questions

computer science

Explain the role of the init process on UNIX and Linux systems in regard to process termination.

Verified answer

computer science

Write code that dynamically allocates an array of 20 integers, then uses a loop to allow the user to enter values for each element of the array.

Verified answer

computer science

The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program. int doSomething(int &x, int &y) { int temp = x; x = y * 10; y = temp * 10; return x + y; }

Verified answer

computer science

Come up with a real-world problem in which only the best solution will do. Then come up with one in which a solution that is “approximately” the best is good enough.

Verified answer

Recommended textbook solutions

Which of the following statement is not true regarding error handling and Logging

Introduction to Algorithms

3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

726 solutions

Which of the following statement is not true regarding error handling and Logging

Information Technology Project Management: Providing Measurable Organizational Value

5th EditionJack T. Marchewka

346 solutions

Which of the following statement is not true regarding error handling and Logging

Information Technology Project Management: Providing Measurable Organizational Value

5th EditionJack T. Marchewka

346 solutions

Which of the following statement is not true regarding error handling and Logging

Service Management: Operations, Strategy, and Information Technology

7th EditionJames Fitzsimmons, Mona Fitzsimmons

103 solutions

Other Quizlet sets

OEC 8

13 terms

MQF - IRC

325 terms

C++

47 terms

Programming 2 Final - Chapters 11, 12, 14

87 terms

What is error handling and logging?

When Error Handling is mentioned, it is referring to the capture of any errors in our application logic that may cause the system to crash, unless handled correctly. On the other hand, logging highlights all the operations and requests that occurred on our system.

What is true about improper error handling?

Improper error handling can enable attacks and lead to unwanted behavior. Parts of the system may receive unintended input, which may result in altered control flow, arbitrary control of a resource, or arbitrary code execution.

Which of the following statements about exception handling is true in Java?

Statement 4: To execute a code with each and every run of the program, the code is written in the finally block. True, Whether an exception is handled or not, the finally block is always run.

What is a handling error?

What Does Error Handling Mean? Error handling refers to the response and recovery procedures from error conditions present in a software application. In other words, it is the process comprised of anticipation, detection and resolution of application errors, programming errors or communication errors.