Difficulty: Easy
Correct Answer: It will output: Exception occurred Remaining program
Explanation:
Introduction / Context:
This question checks your understanding of exception handling flow in C#.NET when invalid user input causes a conversion failure. It focuses on what executes inside a try/catch and what continues after the catch block.
Given Data / Assumptions:
Concept / Approach:
When Convert.ToInt32 receives a non-numeric string, it throws a FormatException. Since the code catches Exception (the base class), this FormatException is caught. Inside the catch block, the program prints "Exception occurred". After the catch completes, control moves beyond the try/catch, where the code prints "Remaining program". Therefore, both messages appear, in that order.
Step-by-Step Solution:
Verification / Alternative check:
If you replaced catch (Exception) with a more specific catch (FormatException), behavior would be identical for this input. Removing the catch would terminate the program and show an unhandled exception message.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming that a catch stops all further execution. Only the protected statements are skipped; code after the try/catch still runs unless the program is terminated or rethrows.
Final Answer:
It will output: Exception occurred Remaining program
Discussion & Comments