question archive 1) The purpose of Exception handling (using try

1) The purpose of Exception handling (using try

Subject:Computer SciencePrice:4.87 Bought7

1) The purpose of Exception handling (using try...catch) is to handle common errors in your program.

- True

- False

2. Which of the following are examples of common exceptions? ( you can choose more than 1 if applicable)

- arithmetic overflow

- division by zero

- memory exhaution

- array index in bounds

3. When a try block is executedbut no exceptions are thrown, where does control pass when the try block has completed axecution?

- The last catch block.

- The finally block, if there is one, otherwise to the code after the last catch.

- The code after the last catch block.

- None of the above.

4. What happens if no catch handler matches the type of a thrown object?

- If there is a finally block, it is axecuted and a search for the match is continued in the next enclosing try statement.( If no match is found, the program thread terminates early).

- The program thread terminates early.

- The exception is ignored.

- None of the above.

5. What happens if multiple catch blocks match the type of thrown object?

- The last one matches the exception is executed.

- The current program thread stops executing.

- The first catch block afterthe try that matches the exception is executed.

- None of the above.

6. The exception thrown by the Scanner class when executing method nextInt, and invalid chars are entered for the int is:

- ArithmeticException

- IndexOutOfBoundsException

- InputMismatchException

- IOException

7. The exception thrown when the program executes a division where the denominator is 0 is:

- IOException

- ArithmeticException

-InputMismatchException

- None of the above

8. The difference between a checked exception and unchecked exception is:

-The compilor verifies that all checked exceptions thrown by each method are caught in the calling code (or declared in a throw clause).

- The JVM verifies that all checked exceptions thrown by each method are caught in the calling code (or declaredin a throw clause).

- Java catches all checked exceptions automatically if the programmer has not done so.

- None of the above.

9. Does declaring a catch of a superclass exception catch all of the subclasses exceptions of that superclass?

- True

- False

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer:

1 - True

Exception handling helps in code execution by handling the common errors that would otherwise result in halting the complete program run.

 

2 - Arithmetic Overflow

Division by zero

Memory Exhaustion

There are many types of common exceptions such as arithmetic overflow, index out of bounds , null pointer , illegal argument exceptions.

 

3 - The finally block, if there is one, otherwise to the code after the last catch

Once the try block is executed the control always goes to the finally block which gets executed even in case when the exception is thrown or not. After the finally block is executed the control goes to the rest of the code after the last catch that was executed.

 

4 - If there is a finally block, it is executed and a search for the match is continued in the next enclosing try statement.( If no match is found, the program thread terminates early)

 

5 - The first catch block after the try that matches the exception is executed

Even if there are multiple catch blocks, the one that is encountered first that is immediately after the try block, gets executed.

 

6 - InputMismatchException

When the invalid characters are entered instead of the defined integer values in the scanner class, it throws the above exception.

 

7 - None of the above

There are no in-built exceptions defined for this type of exception handling.

 

8 - The compiler verifies that all checked exceptions thrown by each method are caught in the calling code

The difference between the checked and unchecked exceptions are , the checked exceptions are checked at compile time while the unchecked exceptions are called at runtime.

 

9 - True

Catching the superclass exceptions also catches the corresponding subclasses exceptions

 

Related Questions