Python Exception Handling Fundamentals Quiz Quiz

  1. Identifying the try Block

    In Python, which block is used to wrap code that may raise an exception?

    1. expect
    2. check
    3. attempt
    4. catch
    5. try
  2. Purpose of the except Block

    Which block handles the exception if one occurs in the corresponding try block?

    1. escape
    2. stop
    3. error
    4. handle
    5. except
  3. Ordering of Code Blocks

    Which of the following is the correct order for try, except, and finally blocks in Python?

    1. try – finally – except
    2. try – except – finally
    3. except – finally – try
    4. finally – try – except
    5. except – try – finally
  4. Catching Multiple Exceptions

    Which syntax allows you to catch multiple different exceptions with one except statement?

    1. except TypeError u0026 ValueError:
    2. except TypeError or ValueError:
    3. except (TypeError, ValueError):
    4. except [TypeError, ValueError]:
    5. except {TypeError, ValueError}:
  5. Using finally for Cleanup

    What is the purpose of the finally block in Python exception handling?

    1. To execute cleanup code regardless of exceptions
    2. To repeat the try block
    3. To catch all exceptions
    4. To terminate the program
    5. To skip code when exceptions occur
  6. Raising an Exception

    Which keyword is used to manually raise an exception in Python?

    1. create
    2. emit
    3. error
    4. throw
    5. raise
  7. Catching All Exceptions

    What type of exception will be caught by 'except Exception:' in Python?

    1. All errors including syntax errors
    2. Only runtime exceptions
    3. Any exception derived from Exception
    4. No exceptions
    5. Syntax errors
  8. Custom Exception Definition

    Which is the correct way to define a custom exception called MyError in Python?

    1. class MyError(Exception): pass
    2. def MyError(): Exception
    3. raise MyError(Exception): pass
    4. class MyError: Exception pass
    5. class MyError: raise Exception
  9. Exception Message Retrieval

    Given 'except Exception as e:', how can you access the error message?

    1. msg(e)
    2. e.message()
    3. e.getError()
    4. get_message(e)
    5. str(e)
  10. Code Execution Flow

    If an exception occurs in a try block and is caught, which following block is always executed?

    1. abort
    2. stop
    3. unless
    4. continue
    5. finally
  11. Syntax Error Handling

    Can 'except Exception:' catch a SyntaxError raised due to a typo in code?

    1. Only if using except SyntaxError
    2. Yes, it catches all errors
    3. Yes, if inside a try block
    4. Only if using except BaseException
    5. No, SyntaxError is not caught
  12. Using else in try/except

    What is the purpose of the else block in try/except/else statements in Python?

    1. To define cleanup code
    2. To rerun the try block
    3. To execute code if no exception occurs
    4. To ignore exceptions
    5. To always run before except
  13. Accessing the Exception Name

    Which option shows a valid way to print the type of an exception caught as 'e'?

    1. print(type(e))
    2. print(type of e)
    3. print(error(e))
    4. print(e.type)
    5. print(e.class)
  14. Custom Exception Raising

    How do you raise your custom exception defined as 'class MyError(Exception): pass'?

    1. MyError() raise
    2. raise new MyError()
    3. throw MyError()
    4. raise MyError()
    5. MyError.raise()
  15. Handling ZeroDivisionError

    Given 'x = 10 / 0', which exception type should be used to catch this error?

    1. ArithmeticErrorr
    2. OverflowError
    3. KeyError
    4. ZeroDivisionError
    5. ValueError