Exception & Error Handling MCQs

Topic-wise practice questions for Programming (C++ / Java / Python). Test your knowledge, check solutions on demand, and pace your preparation.

Zero-leak answer engine • Rate-limited explanations
Practice in Timed Mode
Q1medium
Trace the result of this Java-style math logic:

try:
    int x = 10 / 0
catch (ArithmeticException e):
    x = 0
print(x)
Q2medium
You are using a try-with-resources block (Java) to read a file. When does the file.close() method get called?
Q3medium
What happens if an exception is thrown inside a function, but there is no try-catch block to handle it in that function?
Q4hard
What is the output of the following pseudocode?

function check():
    try:
        print("A")
        return 1
    catch:
        print("B")
    finally:
        print("C")
Q5medium
You are writing a banking app. A user tries to withdraw $100 but only has $50. Which is the most appropriate way to handle this?
Q6medium
Look at this C++ catch sequence. Why is it problematic?

try { ... }
catch (std::exception& e) { ... }
catch (std::runtime_error& e) { ... }
Q7medium
A developer needs to ensure a Database connection is closed even if an SQL error occurs. Which block is dedicated to this "cleanup" logic?
Q8easy
Which of the following is true regarding Errors (like

java.lang.Error)?
Q9easy
What is the primary difference between throw and throws?
Q10medium
In the Java/C# exception hierarchy, which type of exception usually represents a programmer's logic error and does not need to be explicitly declared in the method signature?