Suppressing Exceptions
contextlib.suppress is a clean way to ignore specific exceptions without a try/except block.
contextlib.suppress is a clean way to ignore specific exceptions without a try/except block.
from contextlib import suppress
with suppress(FileNotFoundError):
import os
os.remove("temp.txt")
print("Continued regardless")
Use suppress when you genuinely want to ignore an exception silently.