โ† All HACKERRANK Flashcard Decks

File I/O and Exception Handling Flashcards

7 cards from real HACKERRANK practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 File I/O and Exception Handling flashcards as text
  1. Which Python keyword starts a block that catches exceptions?

    Answer: except

    Python uses `except` (paired with `try`) to catch and handle exceptions, unlike Java/C++ which use `catch`.

  2. Which clause in a try/except construct always executes regardless of whether an exception occurred?

    Answer: finally

    The `finally` clause executes unconditionally after the try and any except blocks, making it ideal for cleanup code.

  3. How do you re-raise the currently-handled exception inside an except block without losing the traceback?

    Answer: raise

    A bare `raise` statement inside an except block re-raises the current exception preserving the original traceback.

  4. What is the base class for all built-in, non-system-exiting exceptions in Python?

    Answer: Exception

    `Exception` is the base class for all built-in exceptions that programs are expected to catch; `BaseException` also includes SystemExit and KeyboardInterrupt.

  5. Which except clause syntax lets you capture the exception instance as a variable named 'e'?

    Answer: except Exception as e:

    The `except ExceptionType as variable:` syntax binds the caught exception instance to the given variable name.

  6. Which block runs only if no exception was raised in the try block?

    Answer: else

    The `else` clause after an except block executes only when the try block completed without raising any exception.

  7. What exception is raised when code tries to divide an integer by zero?

    Answer: ZeroDivisionError

    `ZeroDivisionError` is raised for division or modulo operations where the divisor is zero.