← Back to videos

Junior Python interview: exceptions and try/except

Interview timeline Click any block to jump

Interview breakdown

Interviewer verdict
Needs more practice Level: Intern (below Junior bar for now)

Current knowledge is not yet sufficient for a Junior role (closer to an Intern position): the candidate has only a surface-level grasp of exception mechanics, frequently got stuck on follow-up questions, and mispredicted control flow in the try/except/else/finally snippet. On the positive side, he stayed composed, honestly admitted knowledge gaps without bluffing, and phrased several concepts well in his own words.

Candidate: Egor
Target role: Junior Python Developer

University CS/IT student background, explored several languages, learning Python for a couple of years · first technical interview

Answers accuracy 16 total
50% score
Theory
4/14 correct · 54%
Live coding
0/2 correct · 25%
Practical task
Partially solved

Control flow across try / except / else / finally blocks

The candidate correctly predicted entering except ValueError, skipping else on error, and running finally, but doubted whether else before finally is valid syntax and mistakenly expected execution to resume inside try for print('B') after handling the exception. After running the snippet he deduced why B was skipped, but could not confidently restructure the block.

Topics covered Click a topic to filter questions

Candidate strengths

  • + Honest acknowledgment of knowledge boundaries without bluffing or inventing facts
  • + Clear own-words explanations on several mechanics (ordering of except blocks, binding the exception object with as)
  • + Calm, composed communication throughout his very first technical interview
  • + Accurate self-reflection and realistic assessment of his current gaps

Areas to improve

  • → Master the core purpose of exceptions and when to use try/except vs explicit conditional checks (EAFP vs LBYL)
  • → Learn Python's built-in exception hierarchy and exact class names (BaseException, Exception, ValueError, TypeError, KeyError, ZeroDivisionError)
  • → Practice exact control-flow semantics across try / except / else / finally through hands-on experiments
  • → Build code-reading intuition by writing, breaking, and experimenting with real Python code

Questions in this interview

16 / 16
01 ▶ 03:35
What is an exception in Python and how does it conceptually differ from an error?
Theory Exceptions & debugging
?
Candidate's answer

Described an exception as an unforeseen runtime scenario the program cannot execute normally, but could not clearly distinguish an error from an exception.

Key takeaway

An exception is a runtime signaling object that unwinds the call stack until caught — representing not just fatal errors, but also control-flow events like StopIteration.

Open moment on YouTube ↗
#01
02 ▶ 06:03
Why do we need try/except instead of just checking conditions beforehand with if/else?
Theory Exceptions & debugging
?
Candidate's answer

Explained that try/except prevents crashes and gave a good DB connection example, but got confused under follow-up questioning about when try/except beats if/else.

Key takeaway

Pre-checks (LBYL) cannot prevent external I/O failures or race conditions (TOCTOU) and cannot propagate failure context across multiple call-stack frames like exceptions do.

Open moment on YouTube ↗
#02
03 ▶ 11:03
How much code should go inside a try block, and what should an except handler actually do?
Theory Exceptions & debugging
?
Candidate's answer

Correctly noted that a try block should stay small to isolate specific failure points, but initially reduced exception handling to printing a message or re-prompting user input.

Key takeaway

Keep try blocks minimal around the exact risky call to avoid masking unrelated bugs, and ensure except either recovers cleanly, retries, or logs context and re-raises.

Open moment on YouTube ↗
#03
04 ▶ 14:54
If a user enters zero as a divisor, should you validate it at input time with if or wait for division to fail in try/except?
Theory Control flow, loops & syntactic sugar
?
Candidate's answer

Initially suggested catching the error at the division site, then agreed after discussing wasted intermediate work that expected invalid user input is better validated upfront with if.

Key takeaway

Validate predictable user-input constraints early at system boundaries (fail fast) rather than relying on late runtime exceptions for routine branching.

Open moment on YouTube ↗
#04
05 ▶ 20:23
What built-in exception classes exist in Python and how are they named?
Theory Exceptions & debugging
?
Candidate's answer

Recalled division by zero and arithmetic errors conceptually, but misnamed them ZeroDivisionException and ArithmeticException instead of Python's *Error classes.

Key takeaway

Standard Python runtime exceptions inherit from Exception and follow the *Error naming convention: ValueError, TypeError, KeyError, IndexError, AttributeError, ZeroDivisionError.

Open moment on YouTube ↗
#05
06 ▶ 22:53
Can you define custom exceptions in Python, and which keyword raises them?
Theory Exceptions & debugging
?
Candidate's answer

Correctly stated that custom exceptions are defined as classes and explicitly triggered using the raise keyword.

Key takeaway

Custom domain exceptions should subclass Exception (not BaseException) and are raised via raise MyCustomError('...').

Open moment on YouTube ↗
#06
07 ▶ 24:26
What practical advantage do custom exception classes offer over plain if/elif/else checks?
Theory Exceptions & debugging
?
Candidate's answer

Proposed raising a custom exception for short usernames, but could not articulate why that is preferable to an if/else branch.

Key takeaway

Custom domain exceptions decouple error detection from handling across call layers, carry structured context, and let callers catch specific domain failures without catching unrelated bugs.

Open moment on YouTube ↗
#07
08 ▶ 32:24
Should an except clause catch all exceptions broadly or target specific exception types?
Theory Exceptions & debugging
?
Candidate's answer

Correctly explained that catching everything obscures the root cause, so handlers should specify concrete exception classes across one or more except clauses.

Key takeaway

Broad catch-alls silently swallow bugs like NameError or TypeError; always catch the narrowest applicable exception classes.

Open moment on YouTube ↗
#08
09 ▶ 34:06
If a try block contains two operations that would each raise an exception, will both except blocks run?
Theory Exceptions & debugging
?
Candidate's answer

Wavered between two hypotheses and ultimately guessed that the second except block would also execute.

Key takeaway

The first raised exception immediately aborts the rest of the try suite; at most one matching except clause executes per try statement.

Open moment on YouTube ↗
#09
10 ▶ 36:00
Does the order of multiple except blocks matter?
Theory Exceptions & debugging
?
Candidate's answer

Accurately explained that specific exceptions must come before general ones because placing Exception first catches everything and makes subsequent handlers unreachable.

Key takeaway

Python matches except clauses top-to-bottom using inheritance, so subclasses must always precede their parent exception classes.

Open moment on YouTube ↗
#10
11 ▶ 37:05
How do you inspect a caught exception using 'as', and how does 'except Exception:' differ from a bare 'except:'?
Theory Exceptions & debugging
?
Candidate's answer

Correctly named 'except ... as e' and deduced that the variable holds an Exception/BaseException instance, but mistakenly guessed bare 'except:' skips custom exceptions.

Key takeaway

A bare 'except:' catches BaseException — including SystemExit and KeyboardInterrupt — whereas 'except Exception as err:' safely catches standard and custom application errors.

Open moment on YouTube ↗
#11
12 ▶ 40:18
What are the else and finally clauses in a try statement used for?
Theory Exceptions & debugging
?
Candidate's answer

Named both clauses himself: finally always runs for cleanup (like closing a file), while else runs only when no exception was raised in try.

Key takeaway

The else block runs only if try finishes without raising an exception, keeping follow-up logic outside the scope of try's except handlers.

Open moment on YouTube ↗
#12
13 ▶ 41:27
What happens if another exception is raised inside an except block, and can try/except blocks be nested?
Theory Exceptions & debugging
?
Candidate's answer

Reasoned correctly that an unhandled exception inside except crashes the program and that nested try/except blocks are syntactically valid but hurt readability.

Key takeaway

An exception raised inside except triggers finally first and then propagates outward with automatic exception chaining (__context__).

Open moment on YouTube ↗
#13
14 ▶ 44:10
Is it better to catch an exception inside a function or at its call site?
Theory Functions, scopes & closures
?
Candidate's answer

Chose the call site based on single responsibility, without noting that handling belongs at whichever abstraction layer actually knows how to recover.

Key takeaway

Catch exceptions at the architectural layer that has enough context to decide the recovery strategy rather than swallowing them inside low-level helpers.

Open moment on YouTube ↗
#14
15 ▶ 45:55
What does a snippet with print('A'), raise ValueError, print('B') in try, except ValueError ('C'), else, finally ('D'), and trailing print('E') output?
Live coding Exceptions & debugging
?
Candidate's answer

Doubted else-before-finally syntax, got A, C, skipping else, D, and E right, but wrongly predicted A, C, B, D, E thinking control returns into try after except.

Key takeaway

The required clause order is try -> except -> else -> finally, and raising an exception permanently exits the try block, producing A, C, D, E.

Open moment on YouTube ↗
#15
16 ▶ 51:23
How should this try/except/else/finally snippet be structured so post-operation logic isn't misplaced after a failing line?
Live coding Exceptions & debugging
?
Candidate's answer

Suggested only swapping the lines inside try and admitted he did not understand the role of else well enough to refactor the code.

Key takeaway

Isolate only the risky call inside try, move success-dependent continuation logic into else, and reserve finally for unconditional cleanup.

Open moment on YouTube ↗
#16
Original video description & timecodes

Egor is taking a mock interview for the role of Junior Python Developer. In this episode, we break down exceptions in Python: why we need `try`/`except`, how an error differs from an exception, how `else` and `finally` work, where to handle exceptions correctly, and what happens if the code crashes inside a handler.

The result is an honest analysis of Egor’s first interview: plenty of doubts, unexpected questions, hands-on coding exercises and detailed feedback on how to boost your fundamental knowledge and experience.

Timestamps:

00:00 — Start
00:33 — Introductions and interview format
03:35 — What is an exception in Python
06:03 — Why do we need try/except
11:03 — What code to place inside the try block
20:23 — Types of exceptions: ValueError, TypeError, KeyError and others
22:53 — Custom exceptions and raise
31:42 — How try and except blocks work
36:00 — The order in which exceptions are handled
40:18 — else and finally: why are they needed
41:27 — An error within an except block
44:10 — Where is the best place to handle an exception: within a function or outside it
45:40 — Practical exercise with code
53:20 — Candidate’s self-assessment
55:02 — Feedback on the interview