How should test code handle exceptions without hiding the original failure?
Answer
Catch only when adding context, performing safe cleanup or translating a known boundary. Preserve the cause and stack, avoid broad catch-and-continue behaviour, and let unexpected failures fail the test with relevant artifacts.
Strong answer includes
- preserves original cause
- bounded cleanup
- no silent continuation
Practical example
A test wraps an assertion in a try/catch that logs a warning and continues on any exception, so a real assertion failure gets silently swallowed and the test reports green while the feature is actually broken. Removing the blanket catch and only catching a specific expected cleanup error exposes the real failure immediately.