Skip to content
Preptima

Top 4 Exception handling Interview Questions

Browse 4 real-world technical and behavioral interview questions about Exception handling. Review scenarios, edge cases, and architectural best practices.

A context manager written with @contextmanager leaves a lock held whenever the with body raises. What is missing from the generator?

A try/finally around the yield. @contextmanager throws the body's exception into the generator at the yield, so a release written after the yield is skipped. Wrap the yield in try/finally, or use with lock inside it, and re-raise anything you catch, or the generator suppresses the caller's error.

mediumcoding

Your forwarder says the declaration is lodged and the container has not moved in two days. How do you get visibility into clearance?

Lodged is one state in a sequence and the broker is reporting the only one they volunteer, so you have to enumerate the states, demand a timestamp and a reference for each, and age them. The reason it matters is that storage and container charges accrue from the moment the box lands, and nobody in the chain owns that clock.

hardscenario

The only person who understands the process is leaving in three weeks and nothing is written down. How do you get what you need?

Triage by what is expensive to reconstruct after they leave rather than trying to capture everything, watch the work rather than only interviewing about it, and verify what you are told against system evidence. Capture the decisions and the exceptions, because the happy path can be rebuilt and the judgement cannot.

hardscenario

You await Task.WhenAll over three calls and two of them fail. What does your catch block see?

One exception. WhenAll's task faults with an AggregateException holding every failure, but await rethrows only the first inner exception, so recovering the rest means keeping the WhenAll task in a variable and reading its Exception property.

hardcoding