Exception Handling

Ace your homework & exams now with Quizwiz!

Which statement best describes try block? 1. Encloses code that might throw an exception and the code that should not execute if an exception occurs. 2. Catches and handles an exception 3. Catches and handles an exception 4. Tries the statement within and if fails, corrects the problem.

1. Encloses code that might throw an exception and the code that should not execute if an exception occurs.

In relation to the Termination Model of exception handling which of the following statements is false? 1. Program control resumes just after throw point. 2. Flow of control proceeds to the first statement after the last catch block. 3. None of the statements is true! 4. Program control resumes just after throw point.

1. Program control resumes just after throw point.

What happens when an exception occurs? 1. Try block terminates immediately (expires) and the Program control transfers to first matching catch block. 2. Program control transfers to finally block. 3. The program control transfers to the first statement after all the catch blocks. 4. Program control tries other statements in the try block.

1. Try block terminates immediately (expires) and the Program control transfers to first matching catch block.

Which of the following statements is true about Java Exception Handling? 1. Exception handling enables programmers to create programs that are more robust and fault-tolerant. 2. All of the statements are correct about Java Exception Handling. 3. Exception is an indication of a problem that occurs during a program's execution. 4. Exception handling resolves run-time problems that may occur so program can continue or terminate gracefully.

2. All of the statements are correct about Java Exception Handling.

Which of the following statements is false about checked exceptions: 1. They represent exceptions that inherit from class Exception but not from RuntimeException. 2. Inherit from class RuntimeException or class Error. 3. All statements are false 4. If not caught or declared, compiler error occurs.

2. Inherit from class RuntimeException or class Error. Checked exceptions in Java represent exceptions that inherit from class Exception but not from RuntimeException or Error. Checked exceptions are required to be declared in the method signature or caught using a try-catch block, or else a compiler error occurs.

Which of the following statements is false about uncaught exceptions 1. Uncaught exceptions cause program to terminate if program has only one thread 2. No matter what, uncaught exceptions cause program to terminate. 3. If the program has more than one thread, only current thread is terminated and there may be adverse effects to the rest of the program 4. Uncaught exceptions are exceptions that occur for which there are no matching catch blocks

2. No matter what, uncaught exceptions cause program to terminate.

Exception handling is designed to process the following: 1. Asynchronous errors which occur in parallel with and independent of the program's flow of control 2. Synchronous errors occur when a statement executes 3. Errors during the compilation time.

2. Synchronous errors occur when a statement executes

Which option best describes statements between try block and catch block? You must....... 1. have more than one statements in between try block and catch blocks. 2.not have any statements at all in between try block and catch block/blocks. 3.ignore all the statements in a, b, and c since they all are incorrect statements. 4. have one statement, if you need, in between a try block and the first catch block.

2.not have any statements at all in between try block and catch block/blocks.

A ________ exception is an exception that is checked (notified) by the compiler at compilation-time, these are also called as compile time exceptions.

A checked exception is an exception that is checked (notified) by the compiler at compilation-time, these are also called as compile time exceptions. Checked exceptions: These are exceptions that inherit from the Exception class but not from RuntimeException or Error.

All exception classes are subtypes of the java.lang.__________class.

All exception classes are subtypes of the java.lang.Exception class.

Exceptions may surface through one of the options below: 1. Explicitly mentioned code in a try block. 2. Deeply nested method calls initiated by code in a try block or from the Java 3. Virtual Machine as it executes Java bytecodes. 4. Calls to other methods, 5. All options are correct

All options are correct

__________ are abnormal conditions that happen in case of severe failures, these are not handled by the Java programs. Errors are generated to indicate errors generated by the runtime environment. Example: JVM is out of memory. Normally, programs cannot recover from errors.

Errors are abnormal conditions that happen in case of severe failures, these are not handled by the Java programs. Errors are generated to indicate errors generated by the runtime environment. Example: JVM is out of memory. Normally, programs cannot recover from errors.

Complete this sentence: If a finally block exists it ________________________ 1. Executes only if catch block does not catch an exception. 2. Executes only if catch block catches an exception. 3. Executes only if you call the block programmatically, 4. Executes no matter if catch block catches exception or not.

Executes no matter if catch block catches exception or not.

If a method does not handle a checked exception, the method must declare it using the _______ keyword. The throws keyword appears at the end of a method's signature.

If a method does not handle a checked exception, the method must declare it using the throws keyword. The throws keyword appears at the end of a method's signature.

Java exception handling is managed via five keywords:

Java exception handling is managed via five keywords: try, catch, throw, throws, finally.

The Exception class has two main subclasses: _________ class and ________ Class

The Exception class has two main subclasses: IOException class and RuntimeException Class

Try to understand the difference between throws and throw keywords, ______is used to postpone the handling of a checked exception and ________ is used to invoke an exception explicitly.

Try to understand the difference between throws and throw keywords, throws is used to postpone the handling of a checked exception and throw is used to invoke an exception explicitly.

_________ exceptions − An unchecked exception is an exception that occurs at the time of execution. These are also called as _________ Exceptions. eg NullpointerException

Unchecked exceptions − An unchecked exception is an exception that occurs at the time of execution. These are also called as Runtime Exceptions. RuntimeException and Error are unchecked exceptions, which means they are not required to be caught or declared. Unchecked exceptions inherit from RuntimeException or Error, and usually represent errors that are outside the control of the program or indicate programming errors that should be fixed before running the program.


Related study sets

Bio 2: Prokaryotes, Protists, Fungi

View Set

Speech - Topic Selection and Development (Ch 11)

View Set

Combo with "Evolve : Adolescents" and 5 others

View Set

chapter 15: biomedical therapies

View Set