Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 9 · Error handling depthMis-ordered except clauses — when subclass handlers become dead codepredict135 / 161
+150 XP
Task
📝 **Task:** Predict the exact 4-line output. The chain has `except Exception:` AT THE TOP. Trace each input through the chain and identify which clause actually fires. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

class AppError(Exception):
    pass


class NotFound(AppError):
    pass


class ValidationError(AppError):
    pass


def categorise(exc: Exception) -> str:
    try:
        raise exc
    except Exception:
        return "generic"
    except AppError:
        return "app"
    except NotFound:
        return "not-found"
    except ValidationError:
        return "validation"


print(categorise(NotFound("user 42")))
print(categorise(ValidationError("schema bad")))
print(categorise(AppError("generic")))
print(categorise(ValueError("not ours")))

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…