HomeSubjectsUniversityBlogAbout

Exception & Error Handling

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

Exception handling is a mechanism for detecting and responding to runtime errors so a program can recover or fail in a controlled way instead of crashing. MCQs cover try, catch, finally, throw and throws in Java and C++, and try-except-else-finally in Python. Know checked versus unchecked exceptions, common types such as NullPointerException and IndexOutOfBoundsException, custom exception classes, and how an exception propagates up the call stack until handled. Design questions weigh exceptions against error codes and sentinel values, warn against using exceptions for control flow, and discuss global handlers, fault tolerance and the extra difficulty of handling errors in asynchronous code.

Below are 30 practice questions from a pool of 210 Exception & Error Handling MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Exception & Error HandlingEasy

Q1. What is an exception?

  1. A.A function call to a subroutine in the program
  2. B.An abnormal event disrupting normal program flow✓ Correct
  3. C.A normal expected program event during execution
  4. D.A variable type for storing error code values

Explanation

An exception is an event during execution that disrupts the normal flow.

Report an error in this question

Exception & Error HandlingEasy

Q2. What is a try-catch block?

  1. A.A function definition with parameters and body
  2. B.A looping construct for repeated iteration
  3. C.A construct attempting code and handling exceptions✓ Correct
  4. D.A conditional statement for branching logic

Explanation

A try-catch block executes code in the try section and catches/handles any exceptions in the catch section.

Report an error in this question

Exception & Error HandlingEasy

Q3. What is the purpose of the 'finally' block?

  1. A.To define a new function with a specific name
  2. B.To terminate the program execution immediately
  3. C.To execute code regardless of exception outcome✓ Correct
  4. D.To finalize a variable and prevent changes

Explanation

The finally block always executes after try/catch, whether or not an exception was thrown.

Report an error in this question

Exception & Error HandlingEasy

Q4. What is a NullPointerException?

  1. A.A compile-time syntax error in the code
  2. B.A valid and expected operation result
  3. C.A warning generated by the code linter
  4. D.An exception from using a null reference✓ Correct

Explanation

A NullPointerException occurs when trying to access a member or method on a reference that is null.

Report an error in this question

Exception & Error HandlingEasy

Q5. What does 'throw' do in exception handling?

  1. A.Ignores an exception and continues running
  2. B.Explicitly raises and creates an exception✓ Correct
  3. C.Logs an exception message to the console
  4. D.Catches an exception from the try block

Explanation

The throw keyword explicitly raises an exception, transferring control to the nearest matching catch block.

Report an error in this question

Exception & Error HandlingEasy

Q6. What is an ArithmeticException?

  1. A.A type mismatch between two variable types
  2. B.A file not found error during I/O access
  3. C.An exception for illegal arithmetic operations✓ Correct
  4. D.A syntax error in the source code text

Explanation

ArithmeticException is thrown when an illegal arithmetic operation occurs, most commonly division by zero.

Report an error in this question

Exception & Error HandlingEasy

Q7. What is the difference between compile-time and runtime errors?

  1. A.Compile-time errors cause the running program to crash unexpectedly
  2. B.Runtime errors are detected and caught by the compiler before running
  3. C.Compile-time errors are caught before execution; runtime during it✓ Correct
  4. D.There is no meaningful difference between the two error types

Explanation

Compile-time errors are detected by the compiler before running. Runtime errors occur during program execution.

Report an error in this question

Exception & Error HandlingEasy

Q8. What is an ArrayIndexOutOfBoundsException?

  1. A.A type error from wrong array element types
  2. B.An exception for accessing an invalid index✓ Correct
  3. C.A memory leak from unreleased array memory
  4. D.A valid and expected array access result

Explanation

This exception is thrown when trying to access an array element with an index that is negative or beyond the array length.

Report an error in this question

Exception & Error HandlingEasy

Q9. Can you have multiple catch blocks for one try?

  1. A.Yes, to handle different exception types differently✓ Correct
  2. B.No, only one catch block is allowed per try statement
  3. C.Only for a maximum of exactly two exception types total
  4. D.Only in Python, not in any other programming language

Explanation

Multiple catch blocks can follow a single try block, each handling a different exception type.

Report an error in this question

Exception & Error HandlingEasy

Q10. What is an error message?

  1. A.A variable name used for storing error data
  2. B.A text description about what went wrong✓ Correct
  3. C.A function output returned to calling code
  4. D.A comment written inside the source code

Explanation

An error message is a descriptive text associated with an exception that explains what went wrong.

Report an error in this question

Exception & Error HandlingMedium

Q11. What is the difference between checked and unchecked exceptions in Java?

  1. A.Unchecked exceptions are always more severe than checked exceptions
  2. B.Checked exceptions are always faster to handle than unchecked ones
  3. C.Checked must be declared or caught; unchecked RuntimeExceptions do not✓ Correct
  4. D.There is no meaningful difference between the two exception types

Explanation

Checked exceptions must be either caught or declared. Unchecked exceptions don't require explicit handling.

Report an error in this question

Exception & Error HandlingMedium

Q12. What is exception propagation?

  1. A.Unhandled exception moving up the call stack to find a handler✓ Correct
  2. B.Fixing an exception by catching and logging it
  3. C.Logging all exceptions to a file for later review and analysis
  4. D.Throwing multiple exceptions at the same time from one method

Explanation

When a method doesn't handle an exception, it propagates up the call stack until a handler is found or the program terminates.

Report an error in this question

Exception & Error HandlingMedium

Q13. What is a custom exception?

  1. A.A user-defined exception class for domain-specific errors✓ Correct
  2. B.A syntax error detected during the compilation process
  3. C.A warning generated by the IDE during code development
  4. D.A built-in exception provided by the language runtime

Explanation

Custom exceptions are user-created exception classes for representing specific error conditions in the application domain.

Report an error in this question

Exception & Error HandlingMedium

Q14. What is the 'throws' keyword in Java?

  1. A.A keyword for suppressing exceptions so they are ignored
  2. B.A mechanism for catching and handling thrown exceptions
  3. C.It is exactly the same as the throw keyword in Java
  4. D.A declaration of which checked exceptions a method may throw✓ Correct

Explanation

'throws' in a method signature declares which checked exceptions the method may throw.

Report an error in this question

Exception & Error HandlingMedium

Q15. What is a stack trace?

  1. A.A log file containing all program output and error data
  2. B.The call stack data structure itself in memory
  3. C.A memory dump of the entire program state at crash
  4. D.A report showing the method call chain to an exception✓ Correct

Explanation

A stack trace displays the chain of method calls from the point where the exception occurred, aiding in debugging.

Report an error in this question

Exception & Error HandlingMedium

Q16. What is the purpose of try-with-resources in Java?

  1. A.To automatically close resources when the try block finishes✓ Correct
  2. B.To try executing multiple methods in parallel simultaneously
  3. C.To retry the try block harder if the first attempt fails
  4. D.To allocate additional resources for the try block execution

Explanation

Try-with-resources automatically closes resources that implement AutoCloseable when the try block exits.

Report an error in this question

Exception & Error HandlingMedium

Q17. What is the difference between Error and Exception in Java?

  1. A.Errors are serious JVM problems; Exceptions are recoverable issues✓ Correct
  2. B.Exceptions cannot be caught or handled by any catch block
  3. C.They are the same thing with no meaningful differences at all
  4. D.Errors are less serious and easier to handle than Exceptions

Explanation

Errors represent serious JVM problems. Exceptions represent conditions that applications can reasonably catch and recover from.

Report an error in this question

Exception & Error HandlingMedium

Q18. What is a try-except-else block in Python?

  1. A.An advanced loop construct for iterating with error handling
  2. B.try runs risky code; except handles; else runs if no exception✓ Correct
  3. C.Invalid syntax that causes a compilation error
  4. D.A triple try block for handling three exceptions at once

Explanation

In Python, else after except runs only when no exception was raised in the try block.

Report an error in this question

Exception & Error HandlingMedium

Q19. What is exception chaining?

  1. A.Throwing many exceptions at the same time from one method call
  2. B.Catching exceptions in a specific order from most to least severe
  3. C.Wrapping one exception inside another to preserve original cause✓ Correct
  4. D.A linked list of error objects stored in chronological order

Explanation

Exception chaining wraps the original exception inside a new one, preserving the full error context for debugging.

Report an error in this question

Exception & Error HandlingMedium

Q20. What is the principle of 'fail fast'?

  1. A.Testing the speed of program execution under various load levels
  2. B.Detecting and reporting errors as soon as they occur in the program✓ Correct
  3. C.Making programs crash as quickly as possible for testing purposes
  4. D.Running programs as quickly as possible to improve the performance

Explanation

Fail fast means detecting problems at the earliest possible point and reporting them immediately.

Report an error in this question

Exception & Error HandlingHard

Q21. What is the difference between fault tolerance and exception handling?

  1. A.Exception handling prevents all errors from ever occurring in the program
  2. B.Exception handling manages code errors; fault tolerance is system resilience✓ Correct
  3. C.They are exactly the same concept with no practical differences at all
  4. D.Fault tolerance is always faster and easier to implement than exceptions

Explanation

Exception handling is a programming mechanism for managing errors. Fault tolerance is a broader system design principle for continued operation despite failures.

Report an error in this question

Exception & Error HandlingHard

Q22. What is an exception safety guarantee?

  1. A.A guarantee that no exceptions will ever occur in the program
  2. B.Levels of state guarantees after exception: no-throw, strong, basic✓ Correct
  3. C.A compiler feature that eliminates all runtime exceptions automatically
  4. D.A testing tool that verifies exception handlers work correctly always

Explanation

Exception safety guarantees define what happens to program state when an exception is thrown: no-throw, strong (rollback), basic (valid state), or no guarantee.

Report an error in this question

Exception & Error HandlingHard

Q23. What is the 'catch-all' anti-pattern?

  1. A.A testing pattern for verifying exception handler correctness
  2. B.Catching all exceptions generically which hides bugs in code✓ Correct
  3. C.Catching only specific well-defined exceptions in the code
  4. D.A recommended design pattern for robust exception handling

Explanation

Catching all exceptions with a generic handler masks unexpected errors and makes debugging significantly harder.

Report an error in this question

Exception & Error HandlingHard

Q24. What is the difference between recoverable and unrecoverable errors?

  1. A.There is no meaningful difference between the two error categories
  2. B.All errors in every program are always recoverable with proper code
  3. C.All errors in every program are always unrecoverable without fixes
  4. D.Recoverable errors can be handled; unrecoverable require termination✓ Correct

Explanation

Recoverable errors can be handled gracefully. Unrecoverable errors typically require program termination.

Report an error in this question

Exception & Error HandlingHard

Q25. What is Result/Either type as an alternative to exceptions?

  1. A.A logging mechanism for recording exception messages
  2. B.A type representing either success value or error value✓ Correct
  3. C.A direct replacement for try-catch in all situations
  4. D.A simple boolean type with true or false values

Explanation

Result/Either types encode success or failure in the return type, making error handling explicit and checked at compile time.

Report an error in this question

Exception & Error HandlingHard

Q26. What is the problem with exceptions and concurrency?

  1. A.Exceptions in one thread may not be visible in another thread✓ Correct
  2. B.No problems exist between exceptions and concurrency at all
  3. C.Concurrency completely prevents all exceptions from occurring
  4. D.Exceptions are inherently thread-safe in all implementations

Explanation

In concurrent programming, exceptions in child threads don't automatically propagate to the parent thread.

Report an error in this question

Exception & Error HandlingHard

Q27. What is a panic in Rust/Go?

  1. A.A regular exception like any other in the language
  2. B.A warning message that can be safely ignored by developers
  3. C.An unrecoverable error that unwinds the stack and terminates✓ Correct
  4. D.A debug log entry recorded during program execution review

Explanation

A panic represents an unrecoverable error that unwinds the call stack and terminates the current thread or program.

Report an error in this question

Exception & Error HandlingHard

Q28. What is structured concurrency's approach to exception handling?

  1. A.Ignoring all exceptions thrown by child tasks completely
  2. B.Propagating child exceptions to parent and cancelling siblings✓ Correct
  3. C.Logging exceptions only without any propagation to parents
  4. D.Catching all exceptions silently without any further action

Explanation

Structured concurrency ensures that when a child task fails, its exception propagates to the parent and all sibling tasks are cancelled.

Report an error in this question

Exception & Error HandlingHard

Q29. What is the difference between resumable and non-resumable exceptions?

  1. A.Resumable allows continuing at throw point; non-resumable unwinds✓ Correct
  2. B.There is no meaningful difference between the two exception types
  3. C.Non-resumable exceptions can be resumed after the handler finishes
  4. D.Resumable exceptions are always slower than non-resumable exceptions

Explanation

Non-resumable exceptions unwind the stack. Resumable exceptions allow the handler to fix the issue and resume at the throw point.

Report an error in this question

Exception & Error HandlingHard

Q30. What is the 'exception specification' problem in C++?

  1. A.Exception specifications are completely reliable and always enforced
  2. B.They always improve performance of exception handling in all cases
  3. C.They are required by the C++ standard for every function definition
  4. D.C++ throw() specs were problematic and replaced by noexcept keyword✓ Correct

Explanation

C++ dynamic exception specifications were deprecated because they couldn't be verified at compile time; noexcept is the modern replacement.

Report an error in this question

Ready to test yourself on Exception & Error Handling?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Exception & Error Handling Quiz