Python Developer Interview Question

How do you decide where to catch exceptions and what to do with them?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Catch an exception only where you can actually do something about it: retry, substitute a default, or translate it into a domain error with context. Everywhere else, let it propagate to a single boundary that logs and returns a response. Catch specific types rather than bare except, never swallow silently, and use raise from so the original cause survives in the traceback.

Why interviewers ask this

Exception style tells an interviewer how you will behave during an incident. Sprinkling try except everywhere produces systems that fail quietly and are impossible to debug at three in the morning. They want to hear a deliberate policy about boundaries, specific exception types, preserving the cause chain, and the difference between errors you expect and bugs you should let crash loudly.

How to structure your answer

  • State the rule: catch only where you can act.
  • Describe the single error boundary pattern.
  • Insist on specific types and raise from.
  • Separate expected failures from real bugs.

Example answer

Spoken example, first person

My default is to let things propagate. A try except is only justified if I can retry, fall back to something sensible, or add context the caller needs. Otherwise I am just hiding information. In services I structure it as one error boundary, usually middleware or an exception handler, that logs the full traceback with a request id and returns a clean response, and then the code underneath stays readable because it is not draped in handlers. Inside a module I catch narrow types and translate them into a domain exception with raise from, so the traceback keeps the original cause, since losing that chain is how you end up staring at a stack trace that starts nowhere useful. Bare except is banned in the codebases I run, because it swallows KeyboardInterrupt and SystemExit too. The distinction I care most about is expected failure versus a bug. A timeout on a third party API is expected and gets retried. A KeyError on my own dictionary is a bug and should be loud.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How do you decide between retrying and failing fast?
  • What does an exception group give you?
  • When would you define a custom exception hierarchy?

Related python developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot