PCEP Python Exception Handling Basics Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Questions: 20 | Updated: Aug 16, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What exception occurs with an invalid list index access?

Explanation

Accessing a list with an index outside its valid range raises an `IndexError`, indicating that the requested position does not exist.

Submit
Please wait...
About This Quiz
PCEP Python Exception Handling Basics Quiz - Quiz

Test your understanding of Python exception handling fundamentals. This quiz covers try-except blocks, exception types, raising exceptions, and best practices for error management. Master these core concepts to write robust, fault-tolerant Python code and prepare for the PCEP certification exam.

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. What does catching Exception base class do?

Explanation

In Python, `Exception` is the common base class for most application and runtime errors, so an `except Exception` handler catches many typical failures. However, some important exceptions inherit directly from `BaseException` rather than `Exception`, including `SystemExit`, `KeyboardInterrupt`, and `GeneratorExit`. They are not caught by that handler, helping prevent ordinary error handling from swallowing process-control events.

Submit

3. Which exception occurs when importing a non-existent module?

Explanation

Python raises `ImportError` when an import fails, such as when the requested module cannot be found. In modern Python versions, this specific case may appear as `ModuleNotFoundError`, which is a subclass of `ImportError`.

Submit

4. The ____ clause executes code after try and except, regardless of exceptions.

Explanation

The `finally` clause runs after the `try` and any matching `except` block, whether an exception occurred or not. It is commonly used for cleanup tasks, such as closing files or releasing resources, because its code executes before control leaves the `try` statement.

Submit

5. Can you re-raise an exception in an except block?

Explanation

A bare `raise` statement inside an `except` block re-raises the currently handled exception. It preserves the original exception and its traceback, allowing it to propagate to an outer handler.

Submit

6. Which exception occurs with incompatible operand types?

Explanation

Python raises a TypeError when an operation is applied to operands of unsupported or incompatible types, such as adding a string to an integer. The error indicates that the operation cannot be performed with the supplied values.

Submit

7. What is the purpose of the else clause in try-except?

Explanation

The `else` clause runs after the `try` block only when no exception is raised. It is useful for code that should execute only when the protected operations succeed, while exception handling remains in the `except` clause.

Submit

8. Can you nest try-except blocks inside one another?

Explanation

A try-except block can be placed inside another try or except block. The inner block handles exceptions raised by its statements first; if it cannot handle one, the exception can propagate to the outer handler. This allows different recovery actions at different levels and is valid in languages such as Python.

Submit

9. Which exception is raised for undefined variable names?

Explanation

Python raises a `NameError` when code refers to a name that has not been defined or cannot be found in the current scope. This commonly happens when a variable is used before assignment or its name is misspelled. `ReferenceError` and the other options are not the standard exception for this situation.

Submit

10. How do you capture the exception object in an except block?

Explanation

In Python, `except Exception as var` catches exceptions that are instances of `Exception` and assigns the caught exception object to `var`. You can then inspect its message or other details inside the `except` block. The other forms shown are not valid syntax for capturing an exception object.

Submit

11. What keyword is used to handle exceptions in Python?

Explanation

Python uses the `try` keyword to enclose code that might raise an exception. It is typically followed by an `except` block, which specifies how to handle the exception if one occurs.

Submit

12. Can except blocks be ordered from specific to general exceptions?

Explanation

Specific exception handlers should appear before general ones. A general handler can also match more specific exception types, so placing it first may catch the exception prematurely and prevent the specific handler from running.

Submit

13. What happens if no except block matches the raised exception?

Explanation

If none of the `except` blocks handles a raised exception, it propagates up the call stack. If no surrounding code catches it, the program stops and displays a traceback showing the exception type, message, and where it occurred. A `finally` block may still run, but it does not automatically suppress the exception.

Submit

14. Which exception is raised when converting invalid string to integer?

Explanation

`ValueError` is raised when a string is a valid input type for integer conversion but its contents do not represent a valid integer—for example, `int("hello")`. A `TypeError` would occur if the input itself were of an unsupported type.

Submit

15. Can you have multiple except blocks for one try block?

Explanation

A single `try` block can have multiple `except` blocks to handle different exception types separately. Python checks them in order and runs the first matching handler, so more specific exceptions should generally appear before broader ones.

Submit

16. What exception occurs when accessing a non-existent dictionary key?

Explanation

Python dictionaries raise a `KeyError` when bracket notation is used to access a key that does not exist. To avoid the exception, check whether the key is present or use the dictionary’s `get()` method.

Submit

17. How do you raise an exception explicitly in Python?

Explanation

Use the `raise` keyword to explicitly trigger an exception in Python. `raise Exception()` creates and raises an `Exception` object, which interrupts normal execution unless handled by an appropriate `except` block.

Submit

18. Which exception is raised when dividing by zero?

Explanation

In Python, attempting to divide a number by zero raises a `ZeroDivisionError`. This exception indicates that the division operation is undefined because its divisor is zero.

Submit

19. What is the base class for all built-in exceptions in Python?

Explanation

`BaseException` is the root class of Python’s built-in exception hierarchy. Most common exceptions inherit from `Exception`, which itself inherits from `BaseException`; exceptions such as `SystemExit` and `KeyboardInterrupt` inherit directly from `BaseException`.

Submit

20. Which clause executes regardless of whether an exception occurs?

Explanation

The `finally` clause runs whether an exception occurs or not. It is commonly used for cleanup tasks, such as closing files or releasing resources, after the `try` and any applicable `except` clauses have finished.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What exception occurs with an invalid list index access?
What does catching Exception base class do?
Which exception occurs when importing a non-existent module?
The ____ clause executes code after try and except, regardless of...
Can you re-raise an exception in an except block?
Which exception occurs with incompatible operand types?
What is the purpose of the else clause in try-except?
Can you nest try-except blocks inside one another?
Which exception is raised for undefined variable names?
How do you capture the exception object in an except block?
What keyword is used to handle exceptions in Python?
Can except blocks be ordered from specific to general exceptions?
What happens if no except block matches the raised exception?
Which exception is raised when converting invalid string to integer?
Can you have multiple except blocks for one try block?
What exception occurs when accessing a non-existent dictionary key?
How do you raise an exception explicitly in Python?
Which exception is raised when dividing by zero?
What is the base class for all built-in exceptions in Python?
Which clause executes regardless of whether an exception occurs?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!