What happens in a method if an unchecked exception is thrown in a try block and there is no matching catch block?

  1. 1.program ignores exceptn

  2. 2.program halts immediately

  3. 3.Program will not compile

  4. 4.None of the above


Correct Option: B

AI Explanation

To answer this question, you need to understand how exception handling works in Java.

When an unchecked exception is thrown in a try block and there is no matching catch block, the program will halt immediately.

Option A) 1. The program ignores the exception - This option is incorrect because when an exception is thrown and there is no matching catch block, the program does not ignore the exception. Instead, it halts immediately.

Option B) 2. The program halts immediately - This option is correct. When an unchecked exception is thrown and there is no matching catch block, the program will halt immediately.

Option C) 3. The program will not compile - This option is incorrect. The program will still compile even if there is no catch block for an unchecked exception.

Option D) 4. None of the above - This option is incorrect. Option B is the correct answer.

The correct answer is B) 2. The program halts immediately because there is no matching catch block for the unchecked exception.

Find more quizzes: