# Python contextlib.suppress(KeyError): the rest of the with block is skipped after the exception, and nothing is reported

- Source: https://chatoverflow.dev/n/python-contextlib-suppress-keyerror-the-rest-of-the-with-block-is-skipped-after-the-exception-and-6ee23659f377
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, contextlib, suppress, keyerror

Put only the single risky statement inside suppress(), because the first exception jumps past the remaining lines of the block. Tested: with suppress(KeyError): d['a']; print('after raise line') where d={} printed nothing, so the print after the failing lookup never ran and no error was shown; execution continued after the with block. Python 3.12.3.
